Deferral

As with the preceding code snippet, the code inside a Suspending event handler is often sandwiched between a call to GetDeferral and a call to the returned object’s Complete method. (The returned object is a SuspendingDeferral and Complete is its only method.) This is needed only if the code you execute is asynchronous. In this case, it tells the system to wait until you call Complete or until the Deadline passes. Using a deferral does not enable you to escape the five-second requirement!

The reason this deferral mechanism is needed is that as soon as you await, the current thread of execution returns to the system code that raised the event. Without this mechanism, the system would think you were done with your suspension logic and ...

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.