disappearing messagebox

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)
        Try
            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
        End Try
    End Sub

    Sub OnApplicationExit(ByVal sender As Object, ByVal e As EventArgs)
        If FbInitialized Then FctrlApplication.Deinitialize()
        If ClsCtrlApplication.IsInstantiated(FctrlApplication) Then
            FctrlApplication.Dispose()
        End If
    End Sub

    'This method is the entrypoint of the application.
    Sub Main()
        'Idle event is exploited to start the application controller
        AddHandler Application.Idle, AddressOf OnApplicationIdle
        AddHandler Application.ApplicationExit, AddressOf OnApplicationExit
        Try
            'start main messageloop
            Application.Run()
        Finally
            RemoveHandler Application.ApplicationExit, AddressOf OnApplicationExit
        End Try
    End Sub
LVL 1
IT MeetjeslandAsked:
Who is Participating?
 
Bob LearnedCommented:
You might be able to keep the MessageBox up by using a SystemModal:

Proof of concept in C#:
http://www.codeproject.com/cs/miscctrl/MessageBoxIndirectCS.asp

In Model-View-Controller, the View is the main entity.  The Controller is responsible for two-way communication between the View and the Model.  There should be a strong-bond between the View and the Controller, and in some cases, the View and the Controller are one and the same.

Bob

0
 
Bob LearnedCommented:
I would suggest writing the error to an error log, instead of trying to display a message box.

Bob
0
 
IT MeetjeslandAuthor Commented:
yes, i do that too.  i just removed that code for simplicity.
0
Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

 
IT MeetjeslandAuthor Commented:
I'm very curious now why that messagebox doesn't wait, i never wished more to be able to debug inside the framework as you can in Delphi.

Maybe i should make my own messagebox to find out what's going on.

In the meantime, thanks for replying Bob.

Thomas
0
 
Bob LearnedCommented:
I believe that Application.Exit is rather abrupt and overrides a lot of things.

How would you handle this in Delphi?

Bob
0
 
IT MeetjeslandAuthor Commented:
Calling Application.Exit may not be advisable at a higher level (in forms etc) but not here since nothing is left except for the win-messageloop and that is exactly what Application.Exit() terminates imho.

But the exit() can't have anything to do with the abrupt disappearance of the messagebox.  For all i care, i even may add code to nuke the whole computer.  This code may not be executed until the user clicks the messagebox away.  So, the real and only problem is that the messagebox should idle the mainthread waiting for user input which it doesn't in this case, and that isn't right.

And for your question:
In Delphi, you simply can debug inside the "framework" until you reach API level and this way at least have a much bigger chance to find the reason why the messagebox doesn't wait ( i don't know how it works in delphi 8, never used delphi again since i changed work and switched to VS.NET).

I guess nobody can help me any further on this thread?  Maybe another approach:

I wonder, how do other people implement MVC? Don't you need a central controller that starts other controllers with forms, datamodules, ... ?  How do yóu start the controller first, and not that darn main-form?
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.