public override void DidEnterBackground(UIApplication application) { ourTask = application.BeginBackgroundTask(delegate { //this is the action that will run when the task expires if (ourTask != 0) //this check is because we want to avoid ending the same task twice { application.EndBackgroundTask(ourTask); //end the task ourTask = 0; //reset the id } }); //we start an asynchronous operation //so that we make sure that DidEnterBackground //executes normally new System.Action(delegate { MonoGameGame.EnterBackground(); //Since we are in an asynchronous method, //we have to make sure that EndBackgroundTask //will run on the application's main thread //or we might have unexpected behavior. application.BeginInvokeOnMainThread(delegate { if (ourTask != 0) //same as above { application.EndBackgroundTask(ourTask); ourTask = 0; } }); }).BeginInvoke(null, null); }
/// <Docs>Reference to the UIApplication that invoked this delegate method.</Docs> /// <remarks>Application are allocated approximately 5 seconds to complete this method. Application developers should use this /// time to save user data and tasks, and remove sensitive information from the screen.</remarks> /// <altmember cref="M:MonoTouch.UIKit.UIApplicationDelegate.WillEnterForeground"></altmember> /// <summary> /// Dids the enter background. /// </summary> /// <param name="application">Application.</param> public override void DidEnterBackground(UIApplication application) { Console.WriteLine("DidEnterBackground called..."); // Ask iOS for additional background time and prepare upload. taskId = application.BeginBackgroundTask(delegate { if (taskId != 0) { application.EndBackgroundTask(taskId); taskId = 0; } }); new System.Action(async delegate { await PrepareUpload(); application.BeginInvokeOnMainThread(delegate { if (taskId != 0) { application.EndBackgroundTask(taskId); taskId = 0; } }); }).BeginInvoke(null, null); }
/// <Docs>Reference to the UIApplication that invoked this delegate method.</Docs> /// <remarks>Application are allocated approximately 5 seconds to complete this method. Application developers should use this /// time to save user data and tasks, and remove sensitive information from the screen.</remarks> /// <altmember cref="M:MonoTouch.UIKit.UIApplicationDelegate.WillEnterForeground"></altmember> /// <summary> /// Dids the enter background. /// </summary> /// <param name="application">Application.</param> public override void DidEnterBackground (UIApplication application) { Console.WriteLine("DidEnterBackground called..."); // Ask iOS for additional background time and prepare upload. taskId = application.BeginBackgroundTask (delegate { if (taskId != 0) { application.EndBackgroundTask(taskId); taskId = 0; } }); new System.Action (async delegate { await PrepareUpload(); application.BeginInvokeOnMainThread(delegate { if (taskId != 0) { application.EndBackgroundTask(taskId); taskId = 0; } }); }).BeginInvoke (null, null); }
public override Thread RunInBackground(VoidDelegate task) { ParameterizedThreadStart pts = delegate { int ourTask = 0; UIApplication application = UIApplication.SharedApplication; if (UIDevice.CurrentDevice.IsMultitaskingSupported) { application.BeginBackgroundTask(delegate { //expired if (ourTask != 0) { application.EndBackgroundTask(ourTask); ourTask = 0; } }); } task(); if (ourTask != 0) { application.BeginInvokeOnMainThread(delegate { if (ourTask != 0) //same as above { application.EndBackgroundTask(ourTask); ourTask = 0; } }); } }; Thread t = new Thread(pts); t.Priority = ThreadPriority.Highest; t.IsBackground = true; t.Start(); return(t); }
public override void DidEnterBackground(UIApplication application) { Trace.WriteLine(Trace.kKinskyTouch, "AppDelegate.DidEnterBackground"); int task = 0; task = application.BeginBackgroundTask(delegate { if (task != 0) { application.EndBackgroundTask(task); task = 0; } }); Trace.WriteLine(Trace.kKinskyTouch, "AppDelegate.DidEnterBackground 1"); iScheduler.Schedule(() => { Trace.WriteLine(Trace.kKinskyTouch, "AppDelegate.DidEnterBackground 2"); if (iStackStarted) { Helper.Helper.Stack.Stop(); iStackStarted = false; } Trace.WriteLine(Trace.kKinskyTouch, "AppDelegate.DidEnterBackground 3"); application.BeginInvokeOnMainThread(delegate { Trace.WriteLine(Trace.kKinskyTouch, "AppDelegate.DidEnterBackground 4"); if (task != 0) { application.EndBackgroundTask(task); task = 0; } }); }); Trace.WriteLine(Trace.kKinskyTouch, "AppDelegate.DidEnterBackground 5"); }