Visual Studio 2005: Singleton Class

Updated: Saturday, November 18, 2006


This is the pattern for generating a singleton class: a class which can only be created once.

[VB Code]

Private Class ThisClass
#Region " SINGLETON "
    Private Shared MyInstance As ThisClass
    Private Shared _Lock As New Object
    Public Shared ReadOnly Property Instance() As ThisClass
        Get
            If MyInstance Is Nothing Then
                SyncLock _Lock
                    If (MyInstance Is Nothing) Then MyInstance = New ThisClass
                End SyncLock
            End If
            Return MyInstance
        End Get
    End Property
#End Region
End Class

about

name: Stephen J Whiteley
location: Charleston, SC

stuff
Miscellaneous Articles