Public Class SingleInstance
Inherits System.Windows.Forms.Form
'Static instance all references will use
Private Shared theInstance As SingleInstance
'The constructor is marked as PRIVATE!!!
Private Sub New()
MyBase.New()
InitializeComponent()
End Sub
'Static Property returning the shared instance
Public Shared ReadOnly Property Instance() As SingleInstance
Get
If theInstance Is Nothing Then
theInstance = New SingleInstance
End If
theInstance.Show()
theInstance.BringToFront()
Instance = theInstance
End Get
End Property
Public Class SingleInstance
Inherits System.Windows.Forms.Form
'Static instance all references will use
Private Shared theInstance As SingleInstance
'The constructor is marked as PRIVATE!!!
Private Sub New()
MyBase.New()
InitializeComponent()
End Sub
'Set the Shared Instance to nothing
Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean)
If disposing Then
If Not (components Is Nothing) Then
components.Dispose()
End If
End If
MyBase.Dispose(disposing)
theInstance = Nothing
End Sub
'Static Property returning the shared instance
Public Shared ReadOnly Property Instance() As SingleInstance
Get
If theInstance Is Nothing Then
theInstance = New SingleInstance
End If
theInstance.Show()
theInstance.BringToFront()
Instance = theInstance
End Get
End Property
End Class