protected override void OnStop() { _daemon.Stop(); }
static void Main(string[] args) { try { //Windows service has system32 as default working folder, we change the working dir to install dir for file access System.IO.Directory.SetCurrentDirectory(System.AppDomain.CurrentDomain.BaseDirectory); logger.Debug("Setting current directory to " + System.AppDomain.CurrentDomain.BaseDirectory); var daemon = new WebRTCDaemon(); if (args != null && args.Length == 1 && args[0] == "-i") { try { using (AssemblyInstaller inst = new AssemblyInstaller(typeof(Program).Assembly, args)) { IDictionary state = new Hashtable(); inst.UseNewContext = true; try { inst.Install(state); inst.Commit(state); } catch { try { inst.Rollback(state); } catch { } throw; } } } catch (Exception ex) { Console.Error.WriteLine(ex.Message); } } else if (args != null && args.Length == 1 && args[0] == "-u") { try { using (AssemblyInstaller inst = new AssemblyInstaller(typeof(Program).Assembly, args)) { IDictionary state = new Hashtable(); inst.UseNewContext = true; try { inst.Uninstall(state); } catch { try { inst.Rollback(state); } catch { } throw; } } } catch (Exception ex) { Console.Error.WriteLine(ex.Message); } } else if ((args != null && args.Length == 1 && args[0].StartsWith("-c")) || System.Environment.UserInteractive == true) { Task.Run((Action)daemon.Start); Console.WriteLine("Press q to quit at any time."); while (true) { string option = Console.ReadLine(); if (option?.ToLower() == "q") { Console.WriteLine("User requested quit."); break; } } daemon.Stop(); } else { System.ServiceProcess.ServiceBase[] ServicesToRun; ServicesToRun = new System.ServiceProcess.ServiceBase[] { new WebRTCService(daemon) }; System.ServiceProcess.ServiceBase.Run(ServicesToRun); } } catch (Exception excp) { Console.WriteLine("Exception Main. " + excp); } }