Main Function
[Stathread]
Static void main ()
{
Application. enablevisualstyles ();
Application. setcompatibletextrenderingdefault (false );
Webscreenshot WB = new webscreenshot ();
Process current = process. getcurrentprocess ();
Bool newinstance = true;
Process [] processes = process. getprocessesbyname (current. processname );
// Traverse a routine with the same name running
Foreach (Process in processes)
{
// Ignore existing routines
If (process. ID! = Current. ID)
{
// Ensure that the routine runs from the EXE file
If (assembly. getexecutingassembly (). Location. Replace ("/", "\") = current. mainmodule. filename)
{
// Return another routine instance
Current = process;
Newinstance = false;
Break;
}
}
}
If (newinstance)
{
Application. Run (WB );
}
Else
{
Showwindowasync (current. main1_whandle, 1 );
// Set the actual routine to foreground window
Setforegroundwindow (current. main1_whandle );
}
}
Introduce these two API functions
[Dllimport ("user32.dll")]
Private Static extern bool showwindowasync (intptr hwnd, int cmdshow );
[Dllimport ("user32.dll")]
Private Static extern bool setforegroundwindow (intptr hwnd );
}