Created
September 28, 2017 09:49
-
-
Save NMZivkovic/b62db809dffa2f67266ded6777c74372 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
namespace SingletonExamples | |
{ | |
/// <summary> | |
/// Simple Thread safe solution. | |
/// </summary> | |
public class SingletonThreadSafe | |
{ | |
private static SingletonThreadSafe _instance; | |
private static readonly object _lock = new object(); | |
private SingletonThreadSafe() { } | |
public static SingletonThreadSafe Instance | |
{ | |
get | |
{ | |
lock (_lock) | |
{ | |
if (_instance == null) | |
{ | |
_instance = new SingletonThreadSafe(); | |
} | |
return _instance; | |
} | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment