How to make the app only have one instance

zhaozj2021-02-16  135

This feature can be done using the mutex MUTEX type. See the following code:

[Stathread]

Public static void main (string [] args)

{

// Declare the mutex.

Mutex Mutex = New Mutex (False, "ThissHolDonlyRunon");

// Judgment is in use of the mutex.

Bool Running =! Mutex.waitone (0, False);

IF (! running)

Application.run (New Formlogin ());

Else

MessageBox.show ("Application is already started!");

}

转载请注明原文地址:https://www.9cbs.com/read-8919.html

New Post(0)