简体   繁体   English

Windows Azure管理库1.0.1中调用调用的问题

[英]Issues invoking calls in Windows Azure Management Libraries 1.0.1

When I invoke any async method in the azure management library the application crashes without any exception or other indication. 当我调用azure管理库中的任何异步方法时,应用程序崩溃而没有任何异常或其他指示。 I am using visual studio 2013 .net 4.5 and Windows Azure Management Libraries 1.0.1 我正在使用Visual Studio 2013 .net 4.5和Windows Azure管理库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)
    }
}

Do not use async void ; 不要使用async void ; it has very awkward error handling semantics. 它具有非常尴尬的错误处理语义。 I explain this in more detail in my MSDN article on best practices for asynchronous programming . 我在有关异步编程最佳实践的 MSDN文章中对此进行了更详细的说明。

Instead, use async Task , and ensure that the calling code await s the returned task. 相反,请使用async Task ,并确保调用代码await返回的任务。 This will ensure that your code will observe any exceptions. 这将确保您的代码将遵守任何异常。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Web作业上的Windows Azure管理库认证错误 - Windows Azure Management Libraries Certification Error on Web Jobs 会话管理Windows Azure - session management windows azure Azure管理库虚拟机状态 - azure management libraries virtual machine state 触发异步API调用的Windows窗体中的问题调用操作 - Problem Invoking operations in a Windows Form which triggers async API calls .NET list()的Azure管理库Sdk函数不适用于各种接口 - Azure Management Libraries Sdk for .NET list() function not working for various interfaces 在WebService中找不到Windows Azure管理证书 - Windows Azure Management Certificate not found in WebService 是否有Azure资源管理API调用的C#sdk /包装器? - Is there a C# sdk/wrapper for Azure Resource Management API calls? 在.NET的Azure管理库中创建具有多个声明的Azure服务总线策略 - Create Azure Service Bus policy with multiple claims in Azure Management libraries for .NET 使用REST API或Azure管理库在SQL Azure数据库上执行存储过程 - Executing stored procedures on SQL Azure database using REST API or Azure Management Libraries 如何使用.NET的Azure管理库将Azure SQL数据库还原到时间点 - How to restore an Azure SQL Database to point-in-time using Azure management libraries for .NET
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM