public void RunServerAsService(SimpleServiceBase <T> service) { // Run server as windows service. var ServicesToRun = new ServiceBase[] { service }; Run(ServicesToRun); }
public void RunServer(SimpleServiceBase <T> service) { if (Environment.UserInteractive) { if (InitEnvironment()) { RunServerAsConsole(service, Environment.GetCommandLineArgs()); } } else { RunServerAsService(service); } }
public void RunServerAsConsole(SimpleServiceBase <T> service, string[] args) { srv = service; hr = new SimpleServiceHandler.PHANDLER_ROUTINE(ConsoleCtrlCheck); // Handle CTRL-C, Break, Close, Shut-down, Log-off events so console can be closed properly. SimpleServiceHandler.SetConsoleCtrlHandler(hr, true); //Dim mi As MethodInfo = srv.GetType().GetMethod("OnStart", System.Reflection.BindingFlags.NonPublic Or System.Reflection.BindingFlags.Instance) //mi.Invoke(srv, New Object() {args}) srv.OnStart(args); PauseEnvironment(); // Hold till service is closed properly. while (IsConsole && !IsClosing) { // Logical delay without blocking the current hardware thread. System.Threading.Tasks.Task.Delay(100).Wait(); } }