Wednesday 13 March 2019

Sigleton without lock but follow thread safe in C#

 /// <summary>
    /// Sigleton without lock but follow thread safe
    /// </summary>
    public class SingletonWTLock
    {
        private static readonly Lazy<SingletonWTLock> _mySingleton = new Lazy<SingletonWTLock>(() => new SingletonWTLock());
        private SingletonWTLock() { }
        public static SingletonWTLock Instance
        {
            get
            {
                return _mySingleton.Value;
            }
        }
    }

No comments:

Post a Comment