2014-08-28 51 views
0

我最近正在处理此错误:BeginInvokeStackflowError有没有办法将启动画面扩展为表单显示事件?

我使用的线程,并根据我的研究,这是因为线程。开始()事件中调用.invoke。如果这是在mainform_Load事件中完成的,那么在准备就绪之前,您会收到BeginInvoke错误。

所以我把代码从加载移动到显示的事件。但是,我不希望用户看到背景中有很多内容。在我的代码中有没有办法扩展splashscreen,我必须等到第一次完成显示的主窗口?

Private Sub MainWindow_Shown(sender As Object, e As EventArgs) Handles Me.Shown 
    'update table /search network  
    updateTable() 
    'clean 
    cleanupTable() 
    'fix label 
    updateLabel() 
End Sub 
+0

执行你不希望他们在代码中看到类似于类的用户界面,或者在表单加载/显示之前(在一个类中) – Plutonix 2014-08-28 16:31:04

+0

那么,我移动到显示的事件的线程东西是收集值和为datagridview创建列我正在清理数据表。这些列还没有创建,所以它必须在完成之后。 – Kat 2014-08-28 16:32:38

回答

1

您的应用程序可以启动,而不是由VB Application Framework提供的默认“MainForm”方法。这将使用一个Sub Main为出发点,让您在这之前控制什么形式展示和时,会发生什么:

' IF your form is declared here, it will be 
' available to everything. e.g.: 
' Friend mainfrm As Form1 

Public Sub Main() 
    ' this must be done before any forms/controls are referenced 
    Application.EnableVisualStyles() 

    ' the main form for the app 
    ' just "mainfrm = New Form1" if declared above 
    Dim mainfrm As New Form1 

    ' eye candy for the user 
    Dim splash As New SplashScreen1 
    splash.Show() 

    ' your code here to do stuff. 
    ' you can also invoke your procedures on the main form 
    ' mainfrm.FirstTimeSetup() 

    ' for demo purposes 
    System.Threading.Thread.Sleep(2500) 

    ' close/hide the splash once you are done 
    splash.Close() 
    ' see note 

    ' start the app with the main form 
    Application.Run(mainfrm) 

End Sub 
  • 添加一个模块项目,典型的“程序”
  • 加入您的分主要
  • 转到项目属性,取消使用应用程序框架
  • 选择子主要在启动对象下拉

如果您将启动屏幕声明为顶部的朋友,则可以真正扩展它,直到所有表单的加载事件完成并在那里关闭它。

+0

感谢您的详细解释!我现在正在尝试。 – Kat 2014-08-28 17:48:08

+0

我试过了,解决了一些问题。我想我需要弄清楚的唯一的事情是如何在屏幕上再次在屏幕上使我的加载gif动画(imageanimator不工作,嗯)。否则,运作良好。谢谢 – Kat 2014-08-28 18:16:09

+0

如果你有一个实际的动画GIF,图片框会自动动画。 – Plutonix 2014-08-28 19:58:33

0

有没有办法来扩展启动画面,如果你已经使用项目设置来实现它,但是你可以使用闪屏形式作为初始形式,而不是你的主要形式。至于等待线程完成显示表单(或隐藏初始屏幕),请考虑在主窗体中使用公共布尔值,并在线程完成后将其更改为True。您可以在启动画面上使用计时器检查此布尔变化,然后将窗体的不透明度更改回1.

相关问题