From 767cdc1f6f6a63ce997fc9476911e2c361f9d402 Mon Sep 17 00:00:00 2001 From: LukePulverenti Date: Wed, 20 Feb 2013 20:33:05 -0500 Subject: Pushing missing changes --- MediaBrowser.Common/Events/EventHelper.cs | 104 ++++++++++++++++++++++++++++++ 1 file changed, 104 insertions(+) create mode 100644 MediaBrowser.Common/Events/EventHelper.cs (limited to 'MediaBrowser.Common/Events/EventHelper.cs') diff --git a/MediaBrowser.Common/Events/EventHelper.cs b/MediaBrowser.Common/Events/EventHelper.cs new file mode 100644 index 0000000000..bd2b1156ec --- /dev/null +++ b/MediaBrowser.Common/Events/EventHelper.cs @@ -0,0 +1,104 @@ +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); + } + } + } + } +} -- cgit v1.2.3