diff --git a/articles/stream-analytics/stream-analytics-dotnet-management-sdk.md b/articles/stream-analytics/stream-analytics-dotnet-management-sdk.md index 6bfabb96d50d3..c7f2bf16c5c5d 100644 --- a/articles/stream-analytics/stream-analytics-dotnet-management-sdk.md +++ b/articles/stream-analytics/stream-analytics-dotnet-management-sdk.md @@ -76,7 +76,8 @@ To create an analytics job use the Stream Analytics API for .NET, first set up y using System; using System.Configuration; - using System.Threading; + using System.Threading.Tasks; + using Microsoft.Azure; using Microsoft.Azure.Management.StreamAnalytics; using Microsoft.Azure.Management.StreamAnalytics.Models; @@ -84,40 +85,21 @@ To create an analytics job use the Stream Analytics API for .NET, first set up y 2. Add an authentication helper method: ``` - public static string GetAuthorizationHeader() + private static async Task GetAuthorizationHeader() { - - AuthenticationResult result = null; - var thread = new Thread(() => - { - try - { - var context = new AuthenticationContext( - ConfigurationManager.AppSettings["ActiveDirectoryEndpoint"] + - ConfigurationManager.AppSettings["ActiveDirectoryTenantId"]); - - result = context.AcquireToken( - resource: ConfigurationManager.AppSettings["WindowsManagementUri"], - clientId: ConfigurationManager.AppSettings["AsaClientId"], - redirectUri: new Uri(ConfigurationManager.AppSettings["RedirectUri"]), - promptBehavior: PromptBehavior.Always); - } - catch (Exception threadEx) - { - Console.WriteLine(threadEx.Message); - } - }); - - thread.SetApartmentState(ApartmentState.STA); - thread.Name = "AcquireTokenThread"; - thread.Start(); - thread.Join(); - - if (result != null) - { - return result.AccessToken; - } - + var context = new AuthenticationContext( + ConfigurationManager.AppSettings["ActiveDirectoryEndpoint"] + + ConfigurationManager.AppSettings["ActiveDirectoryTenantId"]); + + AuthenticationResult result = await context.AcquireTokenASync( + resource: ConfigurationManager.AppSettings["WindowsManagementUri"], + clientId: ConfigurationManager.AppSettings["AsaClientId"], + redirectUri: new Uri(ConfigurationManager.AppSettings["RedirectUri"]), + promptBehavior: PromptBehavior.Always); + + if (result != null) + return result.AccessToken; + throw new InvalidOperationException("Failed to acquire token"); } ``` @@ -134,10 +116,9 @@ Add the following code to the beginning of the **Main** method: string streamAnalyticsTransformationName = ""; // Get authentication token - TokenCloudCredentials aadTokenCredentials = - new TokenCloudCredentials( - ConfigurationManager.AppSettings["SubscriptionId"], - GetAuthorizationHeader()); + TokenCloudCredentials aadTokenCredentials = new TokenCloudCredentials( + ConfigurationManager.AppSettings["SubscriptionId"], + GetAuthorizationHeader().Result); // Create Stream Analytics management client StreamAnalyticsManagementClient client = new StreamAnalyticsManagementClient(aadTokenCredentials); @@ -297,8 +278,6 @@ The following sample code starts a Stream Analytics job with a custom output sta LongRunningOperationResponse jobStartResponse = client.StreamingJobs.Start(resourceGroupName, streamAnalyticsJobName, jobStartParameters); - - ## Stop a Stream Analytics job You can stop a running Stream Analytics job by calling the **Stop** method. @@ -311,7 +290,6 @@ The **Delete** method will delete the job as well as the underlying sub-resource // Delete a Stream Analytics job LongRunningOperationResponse jobDeleteResponse = client.StreamingJobs.Delete(resourceGroupName, streamAnalyticsJobName); - ## Get support For further assistance, try our [Azure Stream Analytics forum](https://social.msdn.microsoft.com/Forums/en-US/home?forum=AzureStreamAnalytics).