因此,我正在创建一个应用程序,它将有一个加载资源的闪屏,完成后将加载应用程序的主窗体。在过去,我只是让闪屏拥有线程并保持隐藏,但我正在玩弄让我的主窗体成为线程所有者的想法,但我在窗体之间转换时遇到了麻烦。我目前的方法是
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拥有线程?
发布于 2016-02-27 05:29:37
这是我想出来的,但如果有人有更优雅或更合适的方法,请随时让我知道。
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
我使用后台工作程序处理SplashScreen中的加载
https://stackoverflow.com/questions/35661181
复制相似问题