Hi,
I create one exe using windows application file for convert image,
suppose one more exe going to start mean automatically we won't allow
thorw error message the process already processed.
Loading
Know the answer? Post it. Somebody with the same question will find it here.
Answer a question in the forums and earn +20 SHARP for every answer.
See unanswered questions
DevSocialUpcoming · 3rd editionAI Agents ConferenceDec 1–3, 2026Live onlineFree to attend5days leftRegister
brunda kRank #3,804 · 389 reputationPosted Apr 9, 2012, 2:29 AM EDT
In above url , they have suggested ways to acheive it.
if (Process.GetProcessesByName(Process.GetCurrentProcess().ProcessName).Length > 1)
{
AppLog.Write("Application XXXX already running. Only one instance of this application is allowed", AppLog.LogMessageType.Warn);
return;
}
Keyur Narkhi62 reputationPosted Apr 9, 2012, 2:32 AM EDT
you can use something like that
Process[] notepads = System.Diagnostics.Process.GetProcessesByName("notepad");
int notepadCount = notepads.Length;
Use your exe name if you get count greater than 0 means the process is running
Thanks
Sam HobbsRank #107 · 20.5K reputationPosted Apr 9, 2012, 7:38 AM EDT
Your project has a Program.cs file that has a "Main" method. Open (look at) that file. In it there is a line like:
Application.Run(new Form1());
Add the following lines in the Main method before that line:
Then after the "Application.Run(new Form1())" add the following:
GC.KeepAlive(InstanceMutex);
Also be sure to add a "using System.Threading;" at the beginning of the Program.cs file.