c# - Issues invoking calls in Windows Azure Management Libraries 1.0.1 -
when invoke async method in azure management library application crashes without exception or other indication. using 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 application terminates without 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
; has awkward error handling semantics. explain in more detail in msdn article on best practices asynchronous programming.
instead, use async task
, , ensure calling code await
s returned task. ensure code observe exceptions.
Comments
Post a Comment