Handling the Suspending Event
Visual Studio-generated projects handle Application
’s Suspending
event in a handler called OnSuspending
in App.xaml.cs
. In a Blank App project, however, it’s waiting for you to do something useful:
private void OnSuspending(object sender, SuspendingEventArgs e) { var deferral = e.SuspendingOperation.GetDeferral(); //TODO: Save application state and stop any background activity deferral.Complete(); }
The SuspendingEventArgs
instance has a single SuspendingOperation
property that exposes the GetDeferral
method used in this snippet and a Deadline
property that tells you how long you have to finish your logic in response to this event (currently five seconds).
As for the actual work, ...
Get Universal Windows® Apps with XAML and C# Unleashed now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.