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