首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >C#应用程序线程

C#应用程序线程
EN

Stack Overflow用户
提问于 2016-02-27 04:32:22
回答 1查看 54关注 0票数 0

因此,我正在创建一个应用程序,它将有一个加载资源的闪屏,完成后将加载应用程序的主窗体。在过去,我只是让闪屏拥有线程并保持隐藏,但我正在玩弄让我的主窗体成为线程所有者的想法,但我在窗体之间转换时遇到了麻烦。我目前的方法是

代码语言:javascript
运行
复制
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拥有线程?

EN

回答 1

Stack Overflow用户

发布于 2016-02-27 05:29:37

这是我想出来的,但如果有人有更优雅或更合适的方法,请随时让我知道。

代码语言:javascript
运行
复制
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中的加载

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/35661181

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档