C# ????????????????????
???????????? ???????[ 2013/12/24 16:36:07 ] ??????????????? C#
???????????????????"????????????????"??????????. ????????????????ú???飬???????????????????????μ????????????????????????????????.
???????????????????????(??????????"A.exe")
????1.?????????????????.
????2.??A.exe????????????£????A.exe?????????????A.exe????????????.
????3.????A.exe???????B.exe????A.exe????????????£????B.exe?????A.exe????????????.
??????????????????????????????
????1.????
bool createdNew; Mutex instance
= new Mutex(true??"??????(??????????)"?? out
createdNew);
if
(createdNew)
{
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
Application.Run(new FormMain());
instance.ReleaseMutex();
}
else
{
MessageBox.Show("????????????????????????"?? "?????"?? MessageBoxButtons.OK??
MessageBoxIcon.Error);
Application.Exit();
}
|
????????:
????????????????????????????????ж???????????????????????????????????"????????????????????!".??????????????????????е???????????????????.?????????????:??????????????????(???????????????? ?????????????????????????????????????????????????м?!)
????2.Process??
?????????????????
public static Process RunningInstance()
{
Process current = Process.GetCurrentProcess();
Process[] processes = Process.GetProcessesByName(current.ProcessName);
//Loop through the running processes in with the same name
foreach (Process process in processes)
{
//Ignore the current process
if (process.Id != current.Id)
{
//Make sure that the process is running from the exe file.
if (Assembly.GetExecutingAssembly().Location.Replace("/"?? "") == current.MainModule.FileName)
{
//Return the other process instance.
return process;
}
}
}
//No other instance was found?? return null.
return null;
}
|
??????
![](/images/ad-banner/ad-banner.png)
???·???
??????????????????
2023/3/23 14:23:39???д?ò??????????
2023/3/22 16:17:39????????????????????Щ??
2022/6/14 16:14:27??????????????????????????
2021/10/18 15:37:44???????????????
2021/9/17 15:19:29???·???????·
2021/9/14 15:42:25?????????????
2021/5/28 17:25:47??????APP??????????
2021/5/8 17:01:11