using MediaBrowser.Common.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. public static void QueueEventIfNotNull(EventHandler handler, object sender, EventArgs args) { if (handler != null) { Task.Run(() => { try { handler(sender, args); } catch (Exception ex) { Logger.LogException("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.LogException("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.LogException("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.LogException("Error in event handler", ex); } } } } }