CODE:
Class MyApp
#Region "Shared"
Public Shared Sub main()
Dim mainForm As MyMainForm
Try
mainForm = New MyMainForm
AddHandler Application.ThreadException, AddressOf
CatchUnhandledExceptions
Application.Run(mainForm)
Catch ex As Exception
' This is just for samples - in real programs your default
error processing code should go here
' NOTE: If it gets this far, the next step is that the
program ends
MessageBox.Show(ex.Message, "'Main' Exception Handler")
End Try
End Sub
Private Shared Sub CatchUnhandledExceptions(ByVal sender As Object,
ByVal e As System.Threading.ThreadExceptionEventArgs)
' Again, use your error handling code here
' NOTE: This gets called if you have an unhandled error in the
form event handlers (and possibly other places)
' After this gets executed, the program will
continue.
MessageBox.Show(e.Exception.Message, "Application Thread
Exception Handler")
End Sub
#End Region
End class
COMMENTS:
The recommended manner of starting the program is
Application.Run(mainForm).
There are questions on the NG about using mainForm.ShowDialog() and
while it seems to work there are various comments as to why
Application.Run() is better (a quick search will show them)
hth,
Alan.