using Microsoft.Extensions.Logging; using System; using System.Threading.Tasks; namespace MediaBrowser.Common.Events { /// /// Class EventHelper /// public static class EventHelper { /// /// Fires the event. /// /// The handler. /// The sender. /// The instance containing the event data. /// The logger. public static void QueueEventIfNotNull(EventHandler handler, object sender, EventArgs args, ILogger logger) { if (handler != null) { Task.Run(() => { try { handler(sender, args); } catch (Exception ex) { logger.LogError(ex, "Error in event handler"); } }); } } /// /// Queues the event. /// /// /// The handler. /// The sender. /// The args. /// The logger. public static void QueueEventIfNotNull(EventHandler handler, object sender, T args, ILogger logger) { if (handler != null) { Task.Run(() => { try { handler(sender, args); } catch (Exception ex) { logger.LogError(ex, "Error in event handler"); } }); } } /// /// Fires the event. /// /// The handler. /// The sender. /// The instance containing the event data. /// The logger. public static void FireEventIfNotNull(EventHandler handler, object sender, EventArgs args, ILogger logger) { if (handler != null) { try { handler(sender, args); } catch (Exception ex) { logger.LogError(ex, "Error in event handler"); } } } /// /// Fires the event. /// /// /// The handler. /// The sender. /// The args. /// The logger. public static void FireEventIfNotNull(EventHandler handler, object sender, T args, ILogger logger) { if (handler != null) { try { handler(sender, args); } catch (Exception ex) { logger.LogError(ex, "Error in event handler"); } } } } }