我正在使用WindowsFormsApplicationBase显示一个闪屏。现在,当创建了主窗体并发生错误时,应该会显示一个消息框来通知用户。但是,消息框显示在初始屏幕的下方,因此它不可见。我需要关闭闪屏,这样我才能与用户交互。
下面的代码将给出一个跨线程的操作异常:
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.这有可能吗?
发布于 2011-09-19 21:50:27
如果您的初始屏幕窗体名为mySplashScreen
mySplashScreen.Invoke(new MethodInvoker(delegate {
mySplashScreen.Close();
mySplashScreen.Dispose();
}));发布于 2011-09-19 21:43:21
您不能从创建用户界面元素的线程以外的线程访问这些元素。通常可以使用Control.Invoke从其他线程访问UI元素。
https://stackoverflow.com/questions/7471841
复制相似问题