【问题标题】:Issues invoking calls in Windows Azure Management Libraries 1.0.1在 Windows Azure 管理库 1.0.1 中调用调用的问题
【发布时间】:2014-04-14 12:35:11
【问题描述】:

当我调用 azure 管理库中的任何异步方法时,应用程序崩溃,没有任何异常或其他迹象。我正在使用 Visual Studio 2013 .net 4.5 和 Windows Azure Management Libraries 1.0.1

private static async void ListLocation()
{
     const string filePathCert = @"C:\path\to\certificate";
     var certificate = new X509Certificate2(filePathCert, "password");

     var credentials = new CertificateCloudCredentials("xxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxx", certificate);
     try
     {
         using (ManagementClient client = CloudContext.Clients.CreateManagementClient(credentials))
         {
             var result = await client.Locations.ListAsync(); //Here the application terminates without any message /exception
             var locations = result.Locations;
             foreach (var location in locations)
             {
                 Console.WriteLine("Location: {0}", location.Name);

                 foreach (var feature in location.AvailableServices)
                 {
                     Console.WriteLine(feature);
                 }
             }
        }
    }
    catch(Excepiton ex)
    {
        Debug.WriteLine(ex)
    }
}

【问题讨论】:

    标签: c# .net azure sdk visual-studio-2013


    【解决方案1】:

    不要使用async void;它有非常尴尬的错误处理语义。我在 best practices for asynchronous programming 上的 MSDN 文章中对此进行了更详细的解释。

    改为使用async Task,并确保调用代码awaits 是返回的任务。这将确保您的代码能够观察到任何异常。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2022-11-09
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多