Groups | Blog | Home
all groups > dotnet compact framework > february 2005 >

dotnet compact framework : Singleton Method in VB .NET


Aaron
2/23/2005 6:57:31 PM
Is the singleton method possible in Compact Framework VB .NET? If so,
can anyone tell me how to set it up? I've looked all over the web and
have found VB .NET examples, but they're all convoluted and don't
work. I had a real simple one working in C#, but I don't know how to
accurately translate it. Any help would be appreciated.

Aaron
2/23/2005 8:18:29 PM
Now I feel like an idiot. Since this is my first experience in VB
..NET, I can't even seem to open another form when you click on a
button.

I have a form frmStartup and a button, btnStart. When they tap on the
button, I want the form frmLogin to open using the singleton instance,
but I get nowhere. Can you provide this newbie an example.


On Wed, 23 Feb 2005 20:42:37 -0500, "Tim Wilson"
[quoted text, click to view]
Tim Wilson
2/23/2005 8:42:37 PM
http://www.dofactory.com/Patterns/PatternSingleton.aspx

Public Class Singleton

' Fields
Private Shared internalInstance As Singleton

' Constructor
Protected Sub New()
End Sub

' Methods
Public Shared Function Instance() As Singleton
' Uses "Lazy initialization"
If (internalInstance Is Nothing) Then
internalInstance = New Singleton
End If
Return internalInstance
End Function

End Class

[Usage]
Dim s1 As Singleton = Singleton.Instance()

--
Tim Wilson
..Net Compact Framework MVP

[quoted text, click to view]

AddThis Social Bookmark Button