void Shutdown() { try { if (sharedMemory != null) { sharedMemory.Dispose(); } MessageQueue.CloseAll(transportType); } #pragma warning suppress 56500 // Microsoft, catch block unconditionally fails fast catch (Exception exception) { if (DiagnosticUtility.ShouldTraceError) { ListenerTraceUtility.TraceEvent(TraceEventType.Error, ListenerTraceCode.ServiceShutdownError, SR.GetString(SR.TraceCodeServiceShutdownError), this, exception); } if (Fx.IsFatal(exception)) { throw; } // We exit the service gracefully so that other services that share the process will not be affected. } finally { if (controlServiceHost != null) { controlServiceHost.Abort(); } } }
public void Stop() { try { dealingServiceHost.Close(); dealingSearchServiceHost.Close(); } catch (Exception) { dealingServiceHost.Abort(); dealingSearchServiceHost.Abort(); throw; } }
public void Start() { Console.WriteLine(_serviceName + " starting..."); var openSucceeded = false; try { _serviceHost?.Close(); // ReSharper disable once AssignNullToNotNullAttribute _serviceHost = new DefaultServiceHostFactory().CreateServiceHost( typeof(ICurrencyRatesApiService).AssemblyQualifiedName, new Uri[] { }); } catch (Exception e) { Console.Error.WriteLine("Caught exception while creating " + _serviceName + ": " + e); return; } try { _serviceHost?.Open(); openSucceeded = true; } catch (Exception ex) { Console.Error.WriteLine("Caught exception while starting " + _serviceName + ": " + ex); } finally { if (!openSucceeded) { _serviceHost?.Abort(); } } if (_serviceHost != null && _serviceHost.State == CommunicationState.Opened) { Console.WriteLine(_serviceName + " started"); } else { Console.WriteLine(_serviceName + " failed to open"); var closeSucceeded = false; try { _serviceHost?.Close(); closeSucceeded = true; } catch (Exception ex) { Console.Error.WriteLine("{0} failed to close: {1}", _serviceName, ex); } finally { if (!closeSucceeded) { _serviceHost?.Abort(); } } } }