Exemplo n.º 1
0
        //懒汉式,假如是饿汉式直接调用GetCurrentInstance返回全局静态实例(第一次调用类成员时创建,其他时候均不创建)
        //private static ToolForm tfstatic = new ToolForm();占用启动资源
        public static ToolForm GetCurrentInstance()
        {
            //假如是多线程同时访问该类,同时调用GetCurrentInstance方法时,可能出现创建多个实例
            if (tf == null || tf.IsDisposed)
            {
                //双重加锁
                lock (syncObject)
                {
                    if (tf == null || tf.IsDisposed)
                    {
                        tf           = new ToolForm();
                        tf.MdiParent = Form1.ActiveForm;
                    }
                }
            }

            return(tf);
        }
Exemplo n.º 2
0
 private void button1_Click_1(object sender, EventArgs e)
 {
     ToolForm.GetCurrentInstance().Show();
 }