Q: class

  • Thread starter Thread starter Geoff Jones
  • Start date Start date
G

Geoff Jones

Hi

Can anybody give me some example code of a class which is the first thing
that runs in the application and it then creates and displays an instance of
a form.

Geoff
 
off the top of my head


Public Class MyMainClass

Public Shared Sub Main()
dim aForm as new MyFormName

'you can now do whatever you like with aForm
'if you dont show it modally with showdialog though,
'you will probably hit the end of this sub, and that could be a problem.



End Sub

End Class
 
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.
 
Hi Alan

I can't get your example to compile i.e. CatchUnhandledExceptions causes the
problem:

Argument not specified for parameter 'e' of 'Private Shared Sub
CatchUnhandledExceptions(sender As Object, e As
System.Threading.ThreadExceptionEventArgs)'.

Any ideas?

Geoff
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads


Back
Top