How to get the Process Name in C#?
Hello!
I would like to write an application that can check if my application is running or not? What I know to do is checking the application is in the list of Process or not, e.g. demoapp.exe. I know that in C# we can use Process.GetProcess("demoapp"), but it always prompt for error, why? The following is my supposed method:
private void Monitor()
{
string sProcessName = Process.GetProcess("demoapp");
string sCompare = "demoapp";
if(sProcessName=sCompare)
{
Process.Start("d:\temp\demoapp.exe");
}
else
{
MessageBox.Show("The application is running","Warning");
}
}
Please give me reply asap. Thanks!