public void GetServerRun() { try { bool isPortRunning = false; string exCommand = "npm start"; isPortRunning = UtilityLibrary.PortInUse(port); UtilityLibrary.WriteErrorLog("Port: " + port.ToString() + " Status: " + (isPortRunning ? "Running" : "Not Running")); if (!isPortRunning) { ProcessStartInfo proInf = new ProcessStartInfo(); proInf.FileName = "cmd.exe"; proInf.WorkingDirectory = @"" + apppath + ""; proInf.UseShellExecute = true; proInf.Arguments = "/c " + exCommand; Process proStart = new Process(); proStart.StartInfo = proInf; proStart.Start(); UtilityLibrary.WriteErrorLog("Server listening on Port: " + port.ToString()); } } catch (Exception ex) { ex.ToString(); UtilityLibrary.WriteErrorLog("Error : " + ex.ToString()); } }
protected override void OnStart(string[] args) { timer1 = new Timer(); this.timer1.Interval = interval; this.timer1.Elapsed += new ElapsedEventHandler(this.timer1_Tick); timer1.Enabled = true; UtilityLibrary.WriteErrorLog("Service Started"); }
protected override void OnStop() { timer1.Enabled = false; UtilityLibrary.WriteErrorLog("Service Stopped"); }