/// <summary> /// Stops the server /// </summary> public void Stop() { if (!IsListening) { return; } try { OnBeforeStop?.Invoke(); _stop.Set(); _listening.Join(); foreach (Thread worker in _workers) { worker.Join(); } _listener.Stop(); if (!IsListening) { OnAfterStop?.Invoke(); } } catch (Exception e) { throw new CantStartHostException($"An error occured while trying to stop {GetType().FullName}", e); } }
public Task StopClient() { OnBeforeStop?.Invoke(); _tokenSource.Cancel(); _client.Dispose(); OnAfterStop?.Invoke(); return(Task.CompletedTask); }
public void Stop() { OnBeforeStop?.Invoke(this, EventArgs.Empty); if (Bass.BASS_ChannelStop(ChannelHandle)) { Bass.BASS_StreamFree(ChannelHandle); ChannelHandle = 0; IsActive = false; } OnAfterStop?.Invoke(this, EventArgs.Empty); }
protected void OnAfterStopping() { OnAfterStop?.Invoke(); if (AfterStopping == null) { return; } var exceptions = InvokeServerEventHandlers(AfterStopping.GetInvocationList().Reverse().Cast <ServerEventHandler>()); if (exceptions.Count > 0) { throw new AggregateException(exceptions); } }
public void Stop() { if (_host != null) { lock (_hostSync) { if (_host != null) { var exceptions = new List <Exception>(); try { OnBeforeStop?.Invoke(this, EventArgs.Empty); } catch (Exception exception) { exceptions.Add(exception); } try { _host.Dispose(); } catch (Exception exception) { exceptions.Add(exception); } finally { _host = null; } try { OnAfterStop?.Invoke(this, EventArgs.Empty); } catch (Exception exception) { exceptions.Add(exception); } if (exceptions.Count > 0) { throw new AggregateException(Resources.CannotStopServiceCorrectly, exceptions); } } } } }
public void Stop() { if (!IsListening || IsStopping) { return; } if (IsStarting) { throw new UnableToStopHostException("Cannot stop server until server has finished starting"); } IsStopping = true; try { OnBeforeStop?.Invoke(); StopEvent.Set(); if (!TestingMode) { Listening.Join(); foreach (var worker in Workers) { worker.Join(); } } Listener.Stop(); if (!IsListening) { OnAfterStop?.Invoke(); } } catch (Exception e) { throw new UnableToStopHostException($"An error occured while trying to stop {GetType().FullName}", e); } finally { IsStopping = false; } }