i have this application with a central Controller object that is launched first (before any form, as it should be by default). If anything fails during initialisation an exception is raised, caught and a messagebox is shown. This latter disappears most of the times without having pressed anything. It certainly is shown because i see it pop up but it disappears again very quickly.
Since this is happening before any form is shown, i figured it may have to do something with the fact that i didn't have a messageloop at that moment yet and that the application simply shut down because of the lack of a messageloop, but it appears to be nothing to do with that because, when i changed my code so that i have a loop from the very start, the messagebox still disappeared very fast while my messageloop (and thus application) remains active.
Here's the code. I advise to scroll down to the Main() and then look at the OnApplicationIdle() handler. I use the Application.Idle event to launch everything, i disable the eventhandler after its first call because it only has to run once. I had to do this because i didn't want any form to be the central object, so i had to use Application.Run() instead of Application.Run(myForm).
I hope someone can give me some clues why the message decides to not wanting to be around anymore, because i really don't get this.
Private FctrlApplication As ClsCtrlApplication
Private FbInitialized As Boolean = False
Sub OnApplicationIdle(ByVal sender As Object, ByVal e As EventArgs)
RemoveHandler Application.Idle, AddressOf OnApplicationIdle ' make sure all this is done only once
FctrlApplication = New ClsCtrlApplication(GetType(ClsCtrlApplication).Assembly)
FctrlApplication.Initialize() ' prepares logger, exceptionhandler, ...
FbInitialized = True
FctrlApplication.Execute() ' shows main form
Catch Ex As Exception
MessageBox.Show("A fatal error occurred: " & ClsChars.EOLDbl & Ex.Message, "Fatal error", MessageBoxButtons.OK, MessageBoxIcon.Error) ' this should wait for interaction, but it pops away quite fast
Application.Exit() ' when you drop this line, the application keeps on running after messagebox disappears
Sub OnApplicationExit(ByVal sender As Object, ByVal e As EventArgs)
If FbInitialized Then FctrlApplication.Deinitialize()
If ClsCtrlApplication.IsInstantiated(FctrlApplication) Then
'This method is the entrypoint of the application.
'Idle event is exploited to start the application controller
AddHandler Application.Idle, AddressOf OnApplicationIdle
AddHandler Application.ApplicationExit, AddressOf OnApplicationExit
'start main messageloop
RemoveHandler Application.ApplicationExit, AddressOf OnApplicationExit