有不明白的地方欢迎入群 347636249 探讨
1.using System.Threading;
2.this.btnStartLongRunningTask.TouchUpInside += (s, e) => {
ThreadStart ts = new ThreadStart ( () => { this.DoSomething(); });
ts.Invoke();
};
3.public void DoSomething ()
{
// register our background task
int taskID = UIApplication.SharedApplication.BeginBackgroundTask (() => {
this.BackgroundTaskExpiring ();
});
Console.WriteLine ("Starting background task " + taskID.ToString ());
// sleep for five seconds
Thread.Sleep (5000);
Console.WriteLine ("Background task " + taskID.ToString () + " completed.");
// mark our background task as complete
UIApplication.SharedApplication.EndBackgroundTask (taskID);
}
public void BackgroundTaskExpiring ()
{
Console.WriteLine ("Running out of time to complete you background task!");
}