我最近将我的应用程序从使用自定义 SplashScreen(它只是一个带有 Timer 的表单加载了主表单并自行关闭)更改为 Application Framework。
这是我所做的:
- 创建了一个新的 SplashScreenForm 来显示应用程序版本等。
- 在以下位置选择该表单:我的项目 -> 应用程序 -> SplashScreen
- 将长时间运行的初始化代码从主窗体的构造函数移至 ApplicationEvents 启动事件
这完全符合我的要求。SplashScreen 首先出现,然后 Startup Event 触发并起作用。SplashScreen 关闭并显示实际的主窗体。
到现在为止还挺好。但是我们的客户有时会在启动过程中遇到这个讨厌的异常:
System.InvalidOperationException: Invoke oder BeginInvoke kann für ein Steuerelement erst aufgerufen werden, wenn das Fensterhandle erstellt wurde.
bei System.Windows.Forms.Control.WaitForWaitHandle(WaitHandle waitHandle)
bei System.Windows.Forms.Control.MarshaledInvoke(Control caller, Delegate method, Object[] args, Boolean synchronous)
bei System.Windows.Forms.Control.Invoke(Delegate method, Object[] args)
bei System.Windows.Forms.Control.Invoke(Delegate method)
bei Microsoft.VisualBasic.ApplicationServices.WindowsFormsApplicationBase.HideSplashScreen()
bei Microsoft.VisualBasic.ApplicationServices.WindowsFormsApplicationBase.MainFormLoadingDone(Object sender, EventArgs e)
bei System.EventHandler.Invoke(Object sender, EventArgs e)
bei System.Windows.Forms.Form.OnLoad(EventArgs e)
bei System.Windows.Forms.Form.OnCreateControl()
bei System.Windows.Forms.Control.CreateControl(Boolean fIgnoreVisible)
bei System.Windows.Forms.Control.CreateControl()
bei System.Windows.Forms.Control.WmShowWindow(Message& m)
bei System.Windows.Forms.Control.WndProc(Message& m)
bei System.Windows.Forms.ScrollableControl.WndProc(Message& m)
bei System.Windows.Forms.Form.WmShowWindow(Message& m)
bei System.Windows.Forms.Form.WndProc(Message& m)
bei System.Windows.Forms.Control.ControlNativeWindow.OnMessage(Message& m)
bei System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message& m)
bei System.Windows.Forms.NativeWindow.Callback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)
在 HideSplashScreen() 期间似乎有一个错误,但问题是整个堆栈超出了我的控制范围,所以我不能只捕获这个异常。
有什么建议么?