There’s an implicit rule the handler for that Application.Suspending event must finish within five seconds. This five-second rule is called the deadline. Normally, by having an async call, the present thread would go back to the caller if this hits the await keyword. This is bad within the code above, because the async save technique is unlikely to possess finished when control returns towards the caller and also the software development company will get suspended.
The GetDeferral technique is a housekeeping method employed for this situation. It informs the machine to not finish suspension once the async call returns, but rather to defer suspension until either the entire technique is known as or even the five-second deadline arrives, whichever comes first. Which means that GetDeferral doesn’t really buy you additional time to complete your condition save. It just signifies the way you are handling cleanup before suspension and ensures that you’re given just as much time since you need, up to and including more five seconds, to get this done.
Due to the deadline, you shouldn’t attempt to do an excessive amount of within the OnSuspending handler. One technique for controlling this time around limit would be to save data incrementally because the application condition changes. Key-value pairs could be added progressively for your dictionary object in page navigation occasions. If you work with the MVVM pattern to handle condition, you can even simply stash your view-models within the dictionary like a way to save time.
If everything else fails, you’ll be able to buy additional time to complete your save operation by asking for an ExtendedExecutionSession, though there’s no be certain that the request is going to be honored. Discover more about ?extended execution by going to MSDN.Handling the launch software development company lifecycle condition
We’ve been dealing with the UWP lifecycle a little backwards up up to now. There’s really a very good reason with this. A lot of the data provided within the Application.OnLaunched method, as it happens, handles the way the application was formerly closed.