The above section is the mutex that declares the process
*/
[STAThread]
static void Main ()
{
Try
{
Mymutex = new Mutex (requestinitialownership, "Test", out mutexwascreated);
if (!) ( Requestinitialownership && mutexwascreated))
Mymutex.waitone ();
Else
New Mainapp ();
/*
Here is the implementation of the process mutex. I've seen some people write about mutual exclusion, and they're using it to see if there's a process to start in the current process, and see if it's the same directory as the process you want to run.
In fact, this does not seem to solve the problem completely, for example, if I renamed the program, soft after the directory so that can be run, and the time complexity is too high.
And the above code:
Mymutex = new Mutex (requestinitialownership, "Test", out mutexwascreated);
Here is the request for a named mutex, and returns whether there is already an application with the same name.
if (!) ( Requestinitialownership && mutexwascreated))
Mymutex.waitone ();
If the mutex has already been applied, block the program to run.
This window is the initialization window, or the software wrapper.
MainClass.InitializeForm.InitializeForm initializeform = new MainClass.InitializeForm.InitializeForm ();
Add a validation program to the initialization window, which is typically used to initialize the database
string result;
if (result = Initializeform.starttest ())!= "")
throw new Exception (result);
Else
Initializeform.close ();
End Initialization window, finally enter main window
The above code can achieve all the software startup function, if you want to fill in the landing window, you can put in the initialization window, you can also put in the main window class to implement.
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.