i create some project but when start App. How to Run this App one Process only and name much "test.exe" name only? when Lunch APP ? C# 2.0
-
I'm sorry, I don't get your question. Maybe http://translate.google.com can help you? – Frank Bollack Oct 29 '09 at 11:00
-
1I think he meant a single-instance-only .NET application. Some sort of a singleton process. – o.k.w Oct 29 '09 at 11:04
-
The question isn't clear. Try to rephrase it – Boris Modylevsky Oct 29 '09 at 13:43
2 Answers
Here's a sample project which looks promising: http://www.codeproject.com/KB/cs/SingleInstanceAppMutex.aspx
I quote the goals here:
Goal #1: Prevent a Second Instance from Opening
Goal #2: Activate the First Instance
Goal #3. If the First Instance is Minimized to the System Tray (aka "Notification Area"), Restore It

- 25,490
- 6
- 66
- 63
-
1@monkey_boys: After reading your question a few more times, I'm sort of confused what you actually want. Hah... – o.k.w Oct 29 '09 at 11:05
-
@o.k.w: after reading your answer, I think that you may have successfully interpreted the question. Not sure though. – Fredrik Mörk Oct 29 '09 at 11:06
-
source code very long and not useful can use Process class for check its? – monkey_boys Oct 29 '09 at 11:09
-
-
Again, not entirely sure what it is you are going for, but my interpretation:
If you want to ensure that only a single instance of your process is ever running at once, insert the following code at the beginning of your main method (in Program.cs).
if (Process.GetProcessesByName (Process.GetCurrentProcess().ProcessName).Length > 1)
{
//instance of the process already active, exit
return;
}
You will need to include using System.Diagnostics
at the top of your file.
Note that this is not a perfect solution, in that if a user starts two instances of the process at exactly the same time, then they will both probably close.

- 36,057
- 7
- 42
- 54