我最近将我的应用从使用自定义闪屏屏幕(只是一个带有计时器的表单,加载主表单并关闭自身)改为使用应用程序框架。
似乎在HideSplashScreen()期间出现了错误,但问题是整个堆栈都不受我的控制,所以我不能捕获此异常。有什么建议吗?
这是我所做的:
- 创建了一个新的SplashScreenForm,显示应用程序版本等信息。
- 在“我的项目”->“应用程序”->“闪屏屏幕”中选择该表单
- 将长时间运行的初始化代码从主表单的构造函数移到ApplicationEvents启动事件中
这完全符合我的要求。闪屏屏幕首先出现,然后启动事件触发并进行其工作。闪屏屏幕关闭,实际的主表单出现。
到目前为止一切都很好。但我们的客户有时会在启动时遇到这个令人讨厌的异常:
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()期间出现了错误,但问题是整个堆栈都不受我的控制,所以我不能捕获此异常。有什么建议吗?
MinimumSplashScreenDisplayTime = 3000
,到目前为止,我还没有遇到过这个异常。但由于这个异常是完全随机的,我不能确定它是否有所帮助。 - Jürgen Steinblock