Monotouch中的BeginBackgroundTask [英] BeginBackgroundTask in Monotouch

查看:68
本文介绍了Monotouch中的BeginBackgroundTask的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在应用程序进入后台后,我需要进行一些处理,因此我将以下代码添加到了我的应用程序中:

I need to do some processing after the application enters in the background so I added this code to my app:

public override void DidEnterBackground (UIApplication application)
{
    int taskid = 0;
    taskid = application.BeginBackgroundTask(() => {
        if(taskid != 0)
        {
            System.IO.File.WriteAllText(System.IO.Path.Combine(AppState.Current.User.Path, "blah"), "test");
            application.EndBackgroundTask(taskid);
            taskid = 0;
        }
    });
}

然后,我监视了文件系统(仿真器应用程序),并且文件从未写入目标.有什么原因会发生这种情况吗?我想念什么吗?

Then I monitored the filesystem (the emulator app) and the file never got written to the destination. Is there any reason why this is happening? Am I missing something?

推荐答案

BeginBackgroundTask方法的参数是过期处理程序.它会在您的背景时间到期之前立即执行.那是您应该只结束任务而没有别的地方的地方.

The parameter of BeginBackgroundTask method is the expiration handler. It will be executed right before your background time expires. That is where you should only end the task and nothing else.

在BeginBackgroundTask调用之后,背景时间开始.

It is after the BeginBackgroundTask call where your background time starts.

Apple文档.

iOS上的多任务处理使用MonoTouch.

这篇关于Monotouch中的BeginBackgroundTask的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆