gpt4 book ai didi

c# - 从不同的线程关闭启动画面?

转载 作者:行者123 更新时间:2023-11-30 15:06:41 25 4
gpt4 key购买 nike

我正在使用 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.

这可能吗??

最佳答案

如果您的初始屏幕表单名为 mySplashScreen:

mySplashScreen.Invoke(new MethodInvoker(delegate {
mySplashScreen.Close();
mySplashScreen.Dispose();
}));

关于c# - 从不同的线程关闭启动画面?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7471841/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com