zoukankan      html  css  js  c++  java
  • 比较好的单例登录模式(参考网友)

     
      /// <summary>
      /// 构造函数
      /// </summary> 
      public frmMainForm()
      {
       InitializeComponent();
      }

      #region 比较优化的单例模式

      /// <summary>
      /// 比较优化的单例模式
      /// </summary>
      public static frmMainForm Instance
      {
       get { return Nested.instance; }
      }

      //初始化工作有Nested类的一个静态成员来完成,这样就实现了延迟初始化
      private class Nested
      {
       static Nested()
       {
       }

       internal static readonly frmMainForm instance = new frmMainForm();
      }

      #endregion

       try
       {
        if ((new Login()).ShowDialog() == DialogResult.OK)
        {
         bool createOne;
         
         //同步基元:确保一次只有一个线程使用该资源
         Mutex mut = new Mutex(true, "Thread_Name", out createOne);
         if (createOne)
         {
          //取得主窗口
          Application.Run(frmMainForm.Instance);

          //退出程序
          Application.Exit();

           //释放互斥体的所属权
          mut.ReleaseMutex();
         }
         else
         {
          MessageBox.Show("程序已经运行!", "系统提示");
         }
        }

    非有希望才坚持,坚持才会有希望
  • 相关阅读:
    HRBUST--2317 Game(完全背包)
    k8s的回滚应用
    python练习-2
    k8s HA 补充-(keepalived+haproxy配置)
    Etcd故障恢复记录
    kubernetes 1.14安装部署helm插件
    k8s Prometheus+CAdvisor+node_export+grafana
    k8s ingress部署
    k8s pvc
    k8s pv
  • 原文地址:https://www.cnblogs.com/eugenewu0808/p/Singleton.html
Copyright © 2011-2022 走看看