单例启动程序
string FilePath = Path.Combine(AppDomain.CurrentDomain.SetupInformation.ApplicationBase, AppDomain.CurrentDomain.SetupInformation.ApplicationName);
Assembly asm = Assembly.LoadFrom(FilePath); //当前程序使用Assembly.Load会加载失败
AssemblyCompanyAttribute asmcpn = (AssemblyCompanyAttribute)Attribute.GetCustomAttribute(asm, typeof(AssemblyCompanyAttribute));
bool createdNew;
System.Threading.Mutex _mutex = new System.Threading.Mutex(true, AppDomain.CurrentDomain.SetupInformation.ApplicationName+ asmcpn.Company,out createdNew);
//winform应用程序使用Application获取相关名称
//System.Threading.Mutex _mutex = new System.Threading.Mutex(true, Application.ProductName + Application.CompanyName,out createdNew);
if(createdNew)
{
Console.WriteLine("startNew!");
_mutex.ReleaseMutex();
}
else
{
Console.WriteLine("Procedure is exist!");
}
Console.ReadLine();
浙公网安备 33010602011771号