private void DispatchLoop() { try { _execution.Run(_action, _state); } catch (Exception ex) { #if !NETSTANDARD1_3 if (!(ex is ThreadAbortException) || !AppDomainUnloadMonitor.IsUnloading) #endif { try { _logger.FatalException("Dispatcher is stopped due to an exception, you need to restart the server manually. Please report it to Hangfire developers.", ex); } catch { #if !NETSTANDARD1_3 Trace.WriteLine($"Dispatcher is stopped due to an exception, you need to restart the server manually. Please report it to Hangfire developers: {ex}"); #endif } } } finally { try { _stopped.Signal(); } catch (ObjectDisposedException) { } } }
private void DispatchLoop() { var incrementedRunning = false; try { try { } finally { Interlocked.Increment(ref _running); incrementedRunning = true; } _execution.Run(_action, _state); } catch (Exception ex) { #if !NETSTANDARD1_3 if (!(ex is ThreadAbortException) || !AppDomainUnloadMonitor.IsUnloading) #endif { try { _logger.FatalException("Dispatcher is stopped due to an exception, you need to restart the server manually. Please report it to Hangfire developers.", ex); } catch { #if !NETSTANDARD1_3 Trace.WriteLine($"Dispatcher is stopped due to an exception, you need to restart the server manually. Please report it to Hangfire developers: {ex}"); #endif } } } finally { try { if (incrementedRunning && Interlocked.Decrement(ref _running) == 0) { _stopped.Set(); _stoppedTcs.SetResult(null); } } catch (ObjectDisposedException) { } } }