private void Work(object obj, EventArgs args) { Action action = null; lock (_locker) { if (_queue.Count > 0) { action = _queue.Dequeue(); } } if (action != null) { try { ThreadPool.QueueUserWorkItem( _ => { _semaphore.WaitOne(); try { action.Invoke(); } catch (Exception ex) { MonitoringErrorEventArgs margs = new MonitoringErrorEventArgs { Message = "Возникла ошибка при исполнении метода", Method = action.Method.Name, ErrorMessage = ex.Message }; OnErrorOccured?.Invoke(this, margs); } finally { _semaphore.Release(); } }); } catch (Exception ex) { MonitoringErrorEventArgs margs = new MonitoringErrorEventArgs { Message = "Не удалось поместить метод в очередь выполнения.", Method = action.Method.Name, ErrorMessage = ex.Message }; OnErrorOccured?.Invoke(this, margs); } } }
/// <summary> /// Handles the MonitoringError event of the <see cref="DigipedeClient"/>. /// </summary> /// <param name="sender">The source of the event.</param> /// <param name="e">The <see cref="Digipede.Framework.Api.MonitoringErrorEventArgs"/> instance containing the event data.</param> static void client_MonitoringError(object sender, MonitoringErrorEventArgs e) { Console.WriteLine("Monitoring error raised by the DigipedeClient:{0}", e.Message); }
private static void OnErrorOccured(object obj, MonitoringErrorEventArgs args) { _logger.LogError($"*****При выполнении задач мониторинга возникла ошибка: {args.Message}\n" + $"Метод, вызвавший ошибку: {args.Method}\n" + $"{args.ErrorMessage}"); }