Tag: Otherwise get value visual opens style ESS ODI pre
The reason why this function, is not want to back to the backstage and the front desk to write a set of communication mechanism in the case of lazy way!
Previously found in the main function to write methods, the second launch program to open a new form or show hidden form! Finally found that the main function opened in the new form and the original program is not to share a cache!
So think of a more crooked way, the original form to set the timer and other detection changes, the use of external file changes, the form to show, hide and open, so it is actually open on the original program of the new form!
External files can use anything, Text, config, XML and the like!
This is written in the main function, to detect whether the two-time start:
process[] Processcollection =Process.getprocessesbyname (application.companyname); //If the program process is larger than the program is already running, pop-up the message and make the action, or create the program if(Processcollection. Length >1) { stringss=configurationmanager.appsettings["Mainflag"]; if(ss=="0") {Setconfigvalue ("Mainflag","1"); } } Else{application.enablevisualstyles (); Application.setcompatibletextrenderingdefault (false); //Run the applicationApplication.Run (Newformclient ()); }
This is the check in the timer:
string Mainflag = Getconfigvalue ("mainflag"); if " 1 " ) { setconfigvalue ("mainflag","3 " ); New FormMain (); Fm. Show (); }
When you close the new open form, you need to mark the restore back.
Modify and read config:
/// <summary> ///gets the value of a node in a appsettings/// </summary> /// <param name= "key" ></param> Public Static stringGetconfigvalue (stringkey) {Configuration config=configurationmanager.openexeconfiguration (Configurationuserlevel.none); if(config. Appsettings.settings[key]! =NULL) returnCONFIG. Appsettings.settings[key]. Value; Else return string. Empty; } /// <summary> ///Modify the configuration in appsettings/// </summary> /// <param name= "key" >Key Value</param> /// <param name= "value" >corresponding Value</param> Public Static BOOLSetconfigvalue (stringKeystringvalue) { Try{Configuration config=configurationmanager.openexeconfiguration (Configurationuserlevel.none); if(config. Appsettings.settings[key]! =NULL) config. Appsettings.settings[key]. Value=value; ElseCONFIG. APPSETTINGS.SETTINGS.ADD (key, value); Config. Save (configurationsavemode.modified); Configurationmanager.refreshsection ("appSettings"); return true; } Catch { return false; } }
Do not know whether or not to use external files in a way to achieve this effect! Or have a better way to welcome the Communication Guide!!!
[Winfrom] Use a startup shortcut to open 2 different forms and share a cache space