=========================================================================================================

#region 判断当前程序是否启动,如果已启动则退出,保证只有一个实例启动
bool blnIsRunning;
Mutex mutexApp = new Mutex(false, Assembly.GetExecutingAssembly().FullName, out blnIsRunning);
Console.WriteLine(string.Format("当前运行程序集名称:{0}!", Assembly.GetExecutingAssembly().FullName));
tempLog.Info(string.Format("当前运行程序集名称:{0}!", Assembly.GetExecutingAssembly().FullName));
if (!blnIsRunning)
{
Console.WriteLine("程序已经运行!");
tempLog.Info("程序已经运行!");
return;
}
#endregion

============================================================================================================

#region 懒人的办法,不建议使用

Process[] processes = Process.GetProcessesByName("LoanMatching.DataSys.LoanFormalConsole");

}

#endregion

================================================================================================================

// 以下两种方式是 我在网上搜索到的,没试行不行

 

            //    MessageBoxButtons.OK, MessageBoxIcon.Error);
            //    return;
            //}
代码:
            //            MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
            //            return;
            //        }
            //    }
            //}     

只需要把需要的方法代码放在Void Main()方法中就可以实现..

相关文章: