开发者

How to Run program one Process and some name only?

开发者 https://www.devze.com 2022-12-09 14:48 出处:网络
i create some project but when start App. How to Run this App one Process only and name much \"test.exe\" name onl开发者_如何学Cy? when Lunch APP ?C# 2.0Here\'s a sample project which looks promising:

i create some project but when start App. How to Run this App one Process only and name much "test.exe" name onl开发者_如何学Cy? when Lunch APP ? C# 2.0


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


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.

0

精彩评论

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