Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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