>>This question is a follow up on my earlier Singleton question...
>>
>>How do you make a class Thread-Safe?
>>
>>Would this class be both thread-safe and a singleton?
>>
>>
>>class MyClass
>>{
>> private static readonly object _lockobj = new object();
>>
>> private static MyClass instance = null;
>> public static MyClass Instance
>> {
>> get
>> {
>> if (instance == null)
>> instance = new MyClass();
>>
>> return instance;
>> }
>> }
>>
>> public MyClass()
>> {
>> lock (_lockobj) ;
>> }
>>}
>>
>>
>>Since the class is a singleton, and by getting a lock in the CTOR, is it now thread-safe, assuming I do
>>
>>
>>MyClass class = MyClass.Instance.
>>
>>
>Hi,
>This describes various approaches (including yours):http://www.yoda.arachsys.com/csharp/singleton.html
Fantastic link Viv! I have added some of that to my notebook for reference.
Timothy Bryan