【发布时间】:2010-11-03 21:32:03
【问题描述】:
我有一个 C# 应用程序,当我在加载主窗口之前使用启动屏幕时,它在多线程/后台工作程序方面遇到了麻烦。
我的代码看起来像这样:
[STAThread]
private static void Main()
{
.. do some stuff
ShowSplash(); // where i show a splash screen and load some stuff
...
作为ShowSplash的最后一步,我执行以下操作:
new MyCabApplication<MyMainWorkItem, MDIParentForm>().Run(); -- where i load the form through cab.
问题是,当我这样做时,我得到以下异常:
在单个线程上启动第二个消息循环不是有效操作。改用 Form.ShowDialog
知道我能做什么吗?
这是我的 showsplash 函数:
private static DialogResult ShowSplash(AutoResetEvent controller)
{
// create and register splash screen
splashScreen = new PointSplashScreen();
Application.Run(splashScreen);
return DialogResult.OK;
}
【问题讨论】:
-
在您的示例中包含线程和后台工作人员代码。
-
遵循异常消息中的建议。
-
由于显示启动画面时出现问题,您应该发布
ShowSplash()的实现,以便我们更好地了解它如何最终启动第二个消息循环。 -
在原帖中查看我的splash实现(已编辑)
标签: c# multithreading synchronization