[英]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.