Ejemplo n.º 1
0
        private async Task DispatchLoop()
        {
            try
            {
                await _execution.RunAsync(_action, _state).ConfigureAwait(true);
            }
            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 async Task DispatchLoop()
        {
            var incrementedRunning = false;

            try
            {
                try { }
                finally
                {
                    Interlocked.Increment(ref _running);
                    incrementedRunning = true;
                }

                await _execution.RunAsync(_action, _state).ConfigureAwait(true);
            }
            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)
                {
                }
            }
        }