c# - How do async in window phone? -
in app.xaml.cs
private void application_closing(object sender, closingeventargs e) { a.onendapp(); }in class a
async public static void onendapp() { string temp=await dosomething(); //code here }
i have problem,when close app,and onendapp() method run, when dosomething() run complete , {//code here} not run,but if put a.onendapp() in method run normaly,for example application_launching() method,it run {//code here}
i think when app running no problem,but when app closing run await complete , stop,i want run complete method when close app in async.
after application_closing executed (synchronously), os terminate process. there might short delay before so, , might enough finish writing isolated storage, or might not in case you'll end having corrupted state
i'll take direct quote "beware perils of async/await in application lifecycle event handlers (in fact in any event handlers)" on andy wigley's blog.
calling async code application_deactivated or application_closing
the guidance here “don’t'”. if write apps carefully, can saving changes persistent data go along, shouldn’t have in application lifecycle events.
if must, can try doing this:
someasyncmethod().astask().wait()
if operation completes within timeout period , doesn’t deadlock due needing pump ui thread, work… don’t count on it.
Comments
Post a Comment