/// 构造函数
/// </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("程序已经运行!", "系统提示");
}
}