Write Windows Service in .NET

xiaoxiao2021-03-06  95

Writing and publishing simple Windows Service through the .NET platform is a very convenient thing. New (VB.NET/C#) project, select Windows Service Application .. Then you can add code in the onStart class. If you want to implement Timed operation, live real-time monitoring features, you can use the Timer class supplied by .NET. The following is the code snippet .private void ketimer_elapsed (Object sender, system.timers.ELAPSEDEVENTARGS E) {if (! "}) {Return;} Try {THTIMER.ENABLED = false; myTransaction ();} catch (es.Message);} THTIMER.ENABLED = true;} // Detection Condition Private Bool Excondition () {datetime dtnow = datetime.now ; If (this.currentmode.equals ("auto")) {

String [] frev = this.freqvalue.split ('-'); switch (this.freq) {CASE "2": // 2- per hour IF ((DTNOW.MINUTE == 59) & (DTNow.Second < 30)) {return true;}

Break; Case "4": // 4- Every day, IF ((DTNOW.HOUR == INT.PARS (FREV [1])) & (DTNOW.Minute == Int.Parse (FREV [2])) & DTNOW.SECOND <30)) {Return True;}

Break; Case "8": // 8- Weekly, int We = int.parse (FREV [0] .Substring (1, 1)); if ((DTNOW.DAYOFWEEK.TOSTRING (). Equals (Week [Week " ])) & (DTNOW.HOUR == INT.PARSE (FREV [1])) & (DTNow.minute == INT.PARS (FREV [2])) & (DTNOW.SECOND <30)) {Return True; } Break; Case "16": // 16- per month, int mm = int.parse (frev [0] .substring (1, FREV [0] .length-1)); if ((DTNOW.DAY == MM) & (DTNOW.HOUR == INT.PARSE (FREV [1])) & (DTNow.minute == INT.PARSE (FREV [2])) & (DTNOW.SECOND <30)) {Return True;}

Break; default: // Non-triggered retURN true; break;}} else {switch (this.startPoint) {copy "0": return true; break; default: string [] st = startpoint.split ('-'); IF ((DTNOW.HOUR == INT.PARSE (ST [0])) & (DTNow.minute == INT.PARSE (ST [1])) & (DTNOW.SECOND <30)) {Return True;} Break }}

RETURN FALSE;} Register your Windows Service program. Use installutil IASSERVER.EXE (this file defaults in c: /winnt/microsoft.net/framework/v1.1.4322) InstallUTIL IASSERVER.EXEINSTALLUTIL IASSERVER.EXE / U (Uninstall)

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

New Post(0)