public bool Start(HostControl hostControl) { _log = HostLogger.Get <SampleService>(); _log.Info("SampleService Starting..."); hostControl.RequestAdditionalTime(TimeSpan.FromSeconds(10)); Thread.Sleep(1000); ThreadPool.QueueUserWorkItem(x => { Thread.Sleep(3000); _log.Info("Requesting a restart!!!"); hostControl.Restart(); // _log.Info("Dying an ungraceful death"); // // throw new InvalidOperationException("Oh, what a world."); }); _log.Info("SampleService Started"); return(true); }
/// <summary> /// Simulates the restart command being sent from the service host. /// </summary> public void Restart() { if (_serviceController != null) { _serviceController.Restart(); } }
public bool Start(HostControl hostControl) { _log = HostLogger.Get<SampleService>(); _log.Info("SampleService Starting..."); hostControl.RequestAdditionalTime(TimeSpan.FromSeconds(10)); Thread.Sleep(1000); ThreadPool.QueueUserWorkItem(x => { Thread.Sleep(3000); _log.Info("Requesting a restart!!!"); hostControl.Restart(); // _log.Info("Dying an ungraceful death"); // // throw new InvalidOperationException("Oh, what a world."); }); _log.Info("SampleService Started"); return true; }
public bool Start(HostControl hc) { _hostControl = hc; var hostDirectory = LightBlueConfiguration.SetAsWindowsHost(_settings.ServiceTitle, _settings.Cscfg, _settings.Csdef, _settings.RoleName); Trace.TraceInformation("Worker host service LightBlue context created at directory {0}", hostDirectory); var assemblyPath = Path.IsPathRooted(_settings.Assembly) ? _settings.Assembly : Path.Combine(Environment.CurrentDirectory, _settings.Assembly); var entryPoint = Assembly.LoadFrom(assemblyPath) .GetTypes() .Single(t => typeof(RoleEntryPoint).IsAssignableFrom(t)); _role = (RoleEntryPoint)Activator.CreateInstance(entryPoint); Trace.TraceInformation("Worker host service role entry point {0} located at {1}", entryPoint.FullName, assemblyPath); if (!_role.OnStart()) { Trace.TraceError("Worker host service role entry point {0} start failed", entryPoint.FullName); _hostControl.Restart(); return(true); } Task.Run(() => { try { _role.Run(); } catch (Exception ex) { Trace.TraceError("Worker host service errored with exception: {0}", ex); _hostControl.Restart(); } }); Trace.TraceInformation("Worker host service role entry point {0} running", entryPoint.FullName); return(true); }
public void Restart() { _hostControl.Restart(); }