Created
May 20, 2016 05:21
-
-
Save hieumoscow/7bde368ecd479f8a85bce15fb838ade9 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
nint taskId = -1; | |
Task savingChoiceTask; | |
public async override void DidEnterBackground (UIApplication app) | |
{ | |
Logger.Log ("DidEnterBackground() - entered background"); | |
// Begin Finite-Length Task. | |
this.taskId = app.BeginBackgroundTask (null); | |
// Start saving the user choices. | |
// Note that the method will by default execute on the UI thread. If you go back to the app while the method | |
// is running, you won't see any UI updates and the app will eventually crash. That's why we run it on a separate thread. | |
if (savingChoiceTask == null || savingChoiceTask.IsCompleted) { | |
savingChoiceTask = Task.Run (() => this.SaveUserChoices ()); | |
await savingChoiceTask; | |
} | |
// End Finite-Length Task, finished. | |
if (this.taskId != -1) | |
{ | |
UIApplication.SharedApplication.EndBackgroundTask (this.taskId); | |
this.taskId = -1; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment