2016-02-26 111 views
0

因此,我创建了一个应用程序,该应用程序将具有加载资源的启动画面,完成时将加载该应用程序的主窗体。在过去,我只是让闪屏拥有线程并保持隐藏状态,但是我打算让我的主表单成为线程所有者,但我在表单之间转换时遇到了问题。我目前的做法是C#应用程序线程

void main(String[] args) 
{ 
    ApplicationContext appContext = new ApplicationContext(new SplashScreen()); 
    appContext.ThreadExit += appContext_ThreadExit; 
    Application.Run(appContext); 
} 
place 
private void appContext_ThreadExit(object sender, EventArgs e) 
{ 
    Application.Run(new MainForm()); 
} 

这给我说,你不能启动线程上新的消息循环的错误。那么我该如何正确执行这个过渡?或者我已经通过允许SplashScreen拥有线程来使用最好的方法?

+0

你为什么不使用异步?让启动画面使用async/await加载resurces – Gusman

+0

不会有更多代码有帮助吗?你只是显示有限的代码集 – Seabizkit

回答

0

这是我想出来的,但如果任何人有一个更优雅或正确的方式来做到这一点,随时让我知道。

bool isLoading = true; 

MainForm.OnLoad() 
    -> creates and runs SplashScreen 

MainForm.OnShow() 
    -> if isLoading is true, re-hide 

SplashScreen.LoadingComplete 
    -> event to signal completion of loading events 

MainForm.SplashScreenLoadingComplete 
    -> handler sets isLoading to false 
    -> calls Show() this time form will show 

我处理的闪屏装载有后台工作