VB.NET: What is the best way to ensure that a particular object may be instantiated only once during program execution?
+2
A:
You need a Singleton.
There a great article (unfortunately in C#) here: http://www.yoda.arachsys.com/csharp/singleton.html
But you'll be able to translate to VB quite easily.
You want the 2 last implementations.
further explanations here: http://en.wikipedia.org/wiki/Singleton%5Fpattern
Mike
Mike Gleason jr Couturier
2009-12-27 06:08:37
A:
- Use a module.
- Use this code
_
Class MySpecialClass
Private Sub New()
End Sub
Public ReadOnly SingleInstance As New MySpecialClass
End Class
Edit: WTF? Why is the code formatting broken?
Jonathan Allen
2009-12-27 06:32:30
Adding in a dummy character as above seems to fix it; but it's not clear why one can't go straight from a numbered list into a code section.
Kyralessa
2009-12-27 06:38:30
Thanks......................................
Jonathan Allen
2009-12-28 03:55:58