当前位置: 首页>>代码示例>>C#>>正文


C# UIApplication.BeginBackgroundTask方法代码示例

本文整理汇总了C#中UIApplication.BeginBackgroundTask方法的典型用法代码示例。如果您正苦于以下问题:C# UIApplication.BeginBackgroundTask方法的具体用法?C# UIApplication.BeginBackgroundTask怎么用?C# UIApplication.BeginBackgroundTask使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在UIApplication的用法示例。


在下文中一共展示了UIApplication.BeginBackgroundTask方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: DidEnterBackground

        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);
        }
开发者ID:Grapes,项目名称:MonoGame,代码行数:32,代码来源:Program.cs

示例2: DidEnterBackground

		/// <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);
		}
开发者ID:raghurana,项目名称:SimpleBackgroundUpload,代码行数:33,代码来源:AppDelegate.cs

示例3: DidEnterBackground

        // This method should be used to release shared resources and it should store the application state.
        // If your application supports background exection this method is called instead of WillTerminate
        // when the user quits.
        public override void DidEnterBackground(UIApplication application)
        {
            iOSSensusServiceHelper serviceHelper = SensusServiceHelper.Get() as iOSSensusServiceHelper;

            // app is no longer active, so reset the activation ID
            serviceHelper.ActivationId = null;

            // leave the user a notification if a prompt is currently running
            if (iOSSensusServiceHelper.PromptForInputsRunning)
                serviceHelper.IssueNotificationAsync("Please open to provide responses.", null);

            // save app state in background
            nint saveTaskId = application.BeginBackgroundTask(() =>
                {
                });

            serviceHelper.SaveAsync(() =>
                {
                    application.EndBackgroundTask(saveTaskId);
                });
        }
开发者ID:haunthy,项目名称:sensus,代码行数:24,代码来源:AppDelegate.cs


注:本文中的UIApplication.BeginBackgroundTask方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。