【问题标题】:BeginBackgroundTask in MonotouchMonotouch中的BeginBackgroundTask
【发布时间】:2012-09-22 04:41:35
【问题描述】:

应用进入后台后我需要做一些处理,所以我将这段代码添加到我的应用中:

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;
        }
    });
}

然后我监控了文件系统(模拟器应用程序)并且文件从未被写入目标。发生这种情况有什么原因吗?我错过了什么吗?

【问题讨论】:

    标签: ios5 xamarin.ios


    【解决方案1】:

    BeginBackgroundTask 方法的参数是过期处理程序。它将在您的后台时间到期之前执行。那是你应该只结束任务而不是其他的地方。

    您的后台时间在 BeginBackgroundTask 调用之后开始。

    Apple documentation.

    Multitasking on iOS with MonoTouch.

    【讨论】:

    猜你喜欢
    • 2018-03-15
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多