Skip to content

Instantly share code, notes, and snippets.

@NMZivkovic
Created September 28, 2017 09:49
Show Gist options
  • Save NMZivkovic/b62db809dffa2f67266ded6777c74372 to your computer and use it in GitHub Desktop.
Save NMZivkovic/b62db809dffa2f67266ded6777c74372 to your computer and use it in GitHub Desktop.
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