Ema*_*tta 2 multithreading asynchronous loading xamarin.ios ios
我需要在我的应用程序启动之前加载和处理很多东西,所以当我在我的iPhone上测试时,它总是被iOS杀死,因为它将iPhone挂起太长时间.
然后,我决定为我的应用程序编写一个加载屏幕类,它立即显示一个徽标和一个进度指示器(保持响应以避免被iOS杀死),而在后台,一个单独的线程初始化我的所有ViewControllers然后关闭加载屏幕并显示主窗口.
MonoTouch最好的方法是什么?
任何建议都是受欢迎的.谢谢.
我是这样做的:
在FinishedLaunching方法中,初始化并将初始视图添加到主窗口:
window.AddSubview(this.splashView);
Run Code Online (Sandbox Code Playgroud)
之后,调用您的代码,在线程/异步调用中执行您想要执行的所有操作.我通常使用ThreadPool.记得在主线程上调用:
ThreadPool.QueueUserWorkItem(delegate {
this.BeginInvokeOnMainThread(delegate {
//Initialize stuff here
//...
//when done, add your initial view to the window and remove the splash view
//eg.:
//window.AddSubview(myController.View);
//this.splashView.RemoveFromSuperview();
});
});
// show the window, which only displays the splash view now and return
window.MakeKeyAndVisible();
return true;
Run Code Online (Sandbox Code Playgroud)
一个粗略的例子,但我希望它有所帮助.
| 归档时间: |
|
| 查看次数: |
1547 次 |
| 最近记录: |