开发者

C# Program can only run once + BringToFront if started a 2nd time

I want my program to be startable only once (it doesn't matter if it can be started on other user-accounts).

If its already started and the .exe is opened again it should bring the main-window of the first instance to the front.

What's the easiest way to achieve thi开发者_如何转开发s?


This blog series might be helpful (see other options subsequent parts linked at bottom). I personally like the method described in Part 4 since in the Windows Forms world I've had good success using the WindowsFormsApplicationBase class.


You want to look into using the Mutex object. Basically when your program runs check to see if a Mutex exists the "your unique name", if it does - close application (do this check before loading all resources), otherwise create a Mutex with the unique name and load up your application as planned.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜