Hello,
I'm a longtime reader of this forum and always have been able to find everything I needed, until now as I'm struggling with finding the right code for something.
For my company I'm developing (in framework 3.5) a dll that contains classes, controls, etc. that will be used by all developers here. One of these things is a Splashscreen (called SplashForm). The SplashForm itself contains already logic to test if our DB is available etc. General things that all applications need to test for. It might not be the best practice for a splashscreen to contain code, we just want to avoid writing the same code over and over again.
When I was testing the Splashform I encountered the following problem. If a test fails in the SplashForm I show a message to the user and would quit the application when the user clicks ok. However while the message is being displayed the MainForm of the application continues loading and when that is finished it closes the SplashForm together with the shown messagebox. Normal behaviour I guess as the parent of the messagebox was closed.
I was wondering if there is a way to stop the Mainform from loading when the Splashform is showing a messagebox and thereby stop my Splashform from closing.
Hereby the enshortened code for my SplashForm in the dll:
The code in my test application:
I tried to work with Thread.Join() but this seems to halt everything wherever I use it. I also tried to set the MainForm as owner of the messagebox but this would be closed as well together with the SplashForm. I guess that I could move all the logic in the SplashForm to a Public Shared Class in my dll and call that in the MainForm_Load, I just wanted to avoid additional code in the MainForm. Does anyone here has an idea how or if this is even possible?
PS: Can anyone tell me how to set your code in VB CODE tags instead of the regular ones? I couldn't seem to find the option.
Thanks
I'm a longtime reader of this forum and always have been able to find everything I needed, until now as I'm struggling with finding the right code for something.
For my company I'm developing (in framework 3.5) a dll that contains classes, controls, etc. that will be used by all developers here. One of these things is a Splashscreen (called SplashForm). The SplashForm itself contains already logic to test if our DB is available etc. General things that all applications need to test for. It might not be the best practice for a splashscreen to contain code, we just want to avoid writing the same code over and over again.
When I was testing the Splashform I encountered the following problem. If a test fails in the SplashForm I show a message to the user and would quit the application when the user clicks ok. However while the message is being displayed the MainForm of the application continues loading and when that is finished it closes the SplashForm together with the shown messagebox. Normal behaviour I guess as the parent of the messagebox was closed.
I was wondering if there is a way to stop the Mainform from loading when the Splashform is showing a messagebox and thereby stop my Splashform from closing.
Hereby the enshortened code for my SplashForm in the dll:
Code:
Friend Enum ErrorType
AllOK
Error1
Error2
End Enum
Public Class SplashForm
Private Sub SplashForm_Shown(sender As Object, e As EventArgs) Handles MyBase.Shown
bgWorker.RunWorkerAsync()
End Sub
Private Sub bgWorker_DoWork(sender As Object, e As System.ComponentModel.DoWorkEventArgs) Handles bgWorker.DoWork
'Do Stuff
'if something fails
e.Result = ErrorType.Error1
End Sub
Private Sub bgWorker_RunWorkerCompleted(sender As Object, e As System.ComponentModel.RunWorkerCompletedEventArgs) Handles bgWorker.RunWorkerCompleted
Dim Type As ErrorType = CType(e.Result, ErrorType)
Select Case Type
Case ErrorType.Error1
If MessageBox.Show("Error1", "Error1", MessageBoxButtons.OK, MessageBoxIcon.Error) = Windows.Forms.DialogResult.OK Then
Application.Exit()
End If
Case ErrorType.Error2
If MessageBox.Show("Error2", "Error2", MessageBoxButtons.OK, MessageBoxIcon.Error) = Windows.Forms.DialogResult.OK Then
Application.Exit()
End If
End Select
End Sub
End ClassCode:
Partial Friend Class MyApplication
Protected Overrides Sub OnCreateSplashScreen()
Me.SplashScreen = New Global.EBMCommon.SplashForm()
End Sub
End Class
Public Class MainForm
Private Sub MainForm_Load(sender As Object, e As EventArgs) Handles MyBase.Load
'Load everything necessary
'SplashForm get's closed
End Sub
End ClassPS: Can anyone tell me how to set your code in VB CODE tags instead of the regular ones? I couldn't seem to find the option.
Thanks