문제

I just make an application in C#, but something I don't like. I want to make the application running just one time. Now, if my application is running, when I run the application again, will start another application. I want to make that the application can be running just one time, if you want to run again the application, not create another application, but to start the running application.

Thanks.

도움이 되었습니까?

해결책

Please check this question: Run single instance of an application using Mutex

You are looking for Mutex to check if you application is running. Then find your running application Process and bring it forward.

다른 팁

The way I have achieved this is to use a Mutex. Each instance of the application tries to lock the mutex at startup. If they succeed, they get to run; if they fail, they don't.

The application that doesn't get to run also restores and activates the running instance. This is achieved differently depending on whether it's a WPF or WinForms application.

The advantage to the mutex approach is that it is less prone to race conditions than using FindWindow.

when your application start you have to see the processes that your instance of application is already running or not then make decision according to it.

Possible duplicates :

Detecting a Process is already running in windows using C# .net

How to check already running exe in c#.net?

The concept you are referring is "single instance application". This is usually achieved by named waitable objects, have a look at this article, or this one.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top