public static bool AlreadyRunning()
{
Process current = Process.GetCurrentProcess();
foreach(Process process in Process.GetProcessesByName(current.ProcessName))
{
if (process.Id != current.Id)
{
if(process.MainModule.FileName == current.MainModule.FileName)
{
return true;
}
}
}
return false;
}
{
Process current = Process.GetCurrentProcess();
foreach(Process process in Process.GetProcessesByName(current.ProcessName))
{
if (process.Id != current.Id)
{
if(process.MainModule.FileName == current.MainModule.FileName)
{
return true;
}
}
}
return false;
}
http://dotnet.aspx.cc/ShowDetail.aspx?id=E2A17727-765F-4346-8446-5D130622CB54
try
{
int pid=pro[0].Id;
//MessageBox.Show(i.ToString());
}
catch
{
Directory.SetCurrentDirectory(ds.Tables[0].Rows[i]["dirpath"].ToString());
System.Diagnostics.Process.Start(ds.Tables[0].Rows[i]["apppath"].ToString());
this.listBox1.Items.Add("["+DateTime.Now.ToString()+"]重启:"+ds.Tables[0].Rows[i]["appname"].ToString());
}
{
Mutex stMutex;
bool bCreatedNew = false;
stMutex = new Mutex(true,"MyOneProcMutex",out bCreatedNew);
if(bCreatedNew == true)
{
//Do your work here. }
else
{
MessageBox.Show("Another instance is running, I will quit.");
}
stMutex.Close();
}