cholden
asked on
One App Running at a time
I have a C# app that should not have multiple instances running.
And if there is another instance running then kill the old process and run the one user is currently opening.
Thanks
And if there is another instance running then kill the old process and run the one user is currently opening.
Thanks
Maybe the simplest way:
using System.Diagnostics;
Process[] processes = Process.GetProcessesByName ("myapp");
foreach (Process p in processes)
{
IntPtr pFoundWindow = p.MainWindowHandle;
// Do something with the handle...
p.CloseMainWindow();
}
http://msdn.microsoft.com/ en-us/libr ary/system .diagnosti cs.process .getproces sesbyname. aspx
using System.Diagnostics;
Process[] processes = Process.GetProcessesByName
foreach (Process p in processes)
{
IntPtr pFoundWindow = p.MainWindowHandle;
// Do something with the handle...
p.CloseMainWindow();
}
http://msdn.microsoft.com/
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Ooops... forgot to say, put that code into Program.cs.
ASKER
Axshun I used your code and it seems to work except for my Form1 is hiden and when I run the code it becomes visible.
How can I solve this?
Thanks
How can I solve this?
Thanks
ASKER
Got it thanks Axshun.
http://www.codeproject.com
http://iridescence.no/post