Another way is to implement your own application framework. All you have to do is create a MyApplication class that inherits from the WindowsFormsApplicationBase class.
Imports Microsoft.VisualBasic.ApplicationServices
Module Module1
Sub Main(args As String())
Application.SetCompatibleTextRenderingDefault(False)
Application.SetUnhandledExceptionMode(UnhandledExceptionMode.CatchException)
Dim app As New MyApplication()
AddHandler app.UnhandledException, AddressOf UnhandledExceptionEventHandler
app.Run(args)
End Sub
Sub UnhandledExceptionEventHandler(sender As Object, e As UnhandledExceptionEventArgs)
e.ExitApplication = False
End Sub
Class MyApplication
Inherits WindowsFormsApplicationBase
Public Sub New()
MyBase.New()
IsSingleInstance = False
EnableVisualStyles = True
SaveMySettingsOnExit = True
ShutdownStyle = ShutdownMode.AfterMainFormCloses
End Sub
Private Shared _Form1 As Form1
Public Shared Property Form1 As Form1
Get
If _Form1 Is Nothing Then
_Form1 = New Form1()
End If
Return _Form1
End Get
Set(value As Form1)
_Form1 = value
End Set
End Property
Protected Overrides Sub OnCreateMainForm()
MainForm = Form1
End Sub
End Class
End Module