从另一个线程关闭启动画面? [英] Closing the splash screen from a different thread?
本文介绍了从另一个线程关闭启动画面?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在使用 WindowsFormsApplicationBase 来显示启动画面.现在,在创建主表单并发生错误时,应该显示一个消息框,通知用户.但是,该消息框显示在初始屏幕下,因此它不可见.我需要关闭启动画面,才能与用户互动.
I'm using WindowsFormsApplicationBase to show a splash screen. Now, when the main form is created, and errors occur, a messagebox should be shown informing the user. However, the messagebox is displayed under the splash screen, so it's not visible. I need to close the splash screen so I can interact with the user.
以下代码将给出跨线程操作异常:
The following code will give a cross-thread operation exception :
class SingleInstanceApplication : WindowsFormsApplicationBase
{
private static SingleInstanceApplication instance;
public static void CloseSplash()
{
if (instance.SplashScreen != null)
instance.SplashScreen.Close();
}
}
错误:
Cross-thread operation not valid: Control 'Splash' accessed from a thread
other than the thread it was created on.
这甚至有可能吗?
推荐答案
如果您的初始屏幕表单名为mySplashScreen
:
If your splash screen form is named mySplashScreen
:
mySplashScreen.Invoke(new MethodInvoker(delegate {
mySplashScreen.Close();
mySplashScreen.Dispose();
}));
这篇关于从另一个线程关闭启动画面?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文