public void Start() { Proc = new Process { StartInfo = Psi }; if (RedirectMode) { Proc.OutputDataReceived += OutPut; Proc.ErrorDataReceived += OutPut; } Proc.Exited += OnExit; Proc.EnableRaisingEvents = true; try { Proc.Start(); } catch (Exception ex) { Conf.Abort($"Failed to create Worker `{Conf.Worker}` in `{Conf.WorkingDir}`:\r\n{ex}"); } Conf.Info($"Created Worker `{Conf.Worker}` in `{Conf.WorkingDir}`"); if (RedirectMode) { Proc.BeginErrorReadLine(); Proc.BeginOutputReadLine(); } }
protected override void OnStart(string[] args) { try { var svcDescription = SvcUtils.GetServiceDescriptionInSvcBin(); var i = svcDescription.LastIndexOf('<') + 1; var n = svcDescription.Length - 1 - i; var cwd = svcDescription.Substring(i, n); Libs.SetCwd(cwd); } catch (Exception ex) { Libs.Dump($"Failed to set cwd from service's description:\r\n{ex}"); Environment.Exit(1); } Conf = new Conf(false); try { Worker = new Worker(Conf, true); Worker.Start(); } catch (Exception ex) { Conf.Abort($"Failed to start the worker:\r\n{ex}"); } }
protected override void OnStop() { try { Worker.Stop(); } catch (Exception ex) { Conf.Abort($"Failed to stop the worker:\r\n{ex}"); } }