1.单例(满足多线程)

 public class
   {
        private static SingelDesign _intance = null;
        private static readonly object _lock = new object();

        public static SingelDesign Intance
        {
            get
            {
                return _intance;
            }

            set
            {
                _intance = value;
            }
        }

        public static SingelDesign Get()
        {
            if (Intance == null)//这个判断为了多线程节省资源
            {
                lock (_lock)//加锁为了线程安全
                {
                    if (Intance == null)
                    {
                        Intance = new SingelDesign();
                    }
                }
            }
            return Intance;
        }
        private SingelDesign() { }
    }

2.调用

SingelDesign.Get();

 

相关文章:

  • 2021-12-29
  • 2021-11-17
  • 2022-12-23
  • 2021-09-13
  • 2021-12-15
  • 2021-08-01
  • 2021-12-10
猜你喜欢
  • 2022-02-08
  • 2022-12-23
  • 2021-09-20
  • 2022-12-23
  • 2021-06-23
  • 2022-01-21
  • 2021-05-26
相关资源
相似解决方案