diff options
| author | LukePulverenti <luke.pulverenti@gmail.com> | 2013-02-20 20:33:05 -0500 |
|---|---|---|
| committer | LukePulverenti <luke.pulverenti@gmail.com> | 2013-02-20 20:33:05 -0500 |
| commit | 767cdc1f6f6a63ce997fc9476911e2c361f9d402 (patch) | |
| tree | 49add55976f895441167c66cfa95e5c7688d18ce /MediaBrowser.Common/Events | |
| parent | 845554722efaed872948a9e0f7202e3ef52f1b6e (diff) | |
Pushing missing changes
Diffstat (limited to 'MediaBrowser.Common/Events')
| -rw-r--r-- | MediaBrowser.Common/Events/EventHelper.cs | 104 | ||||
| -rw-r--r-- | MediaBrowser.Common/Events/GenericEventArgs.cs | 29 |
2 files changed, 121 insertions, 12 deletions
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 +{ + /// <summary> + /// Class EventHelper + /// </summary> + public static class EventHelper + { + /// <summary> + /// Fires the event. + /// </summary> + /// <param name="handler">The handler.</param> + /// <param name="sender">The sender.</param> + /// <param name="args">The <see cref="EventArgs" /> instance containing the event data.</param> + 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); + } + }); + } + } + + /// <summary> + /// Queues the event. + /// </summary> + /// <typeparam name="T"></typeparam> + /// <param name="handler">The handler.</param> + /// <param name="sender">The sender.</param> + /// <param name="args">The args.</param> + public static void QueueEventIfNotNull<T>(EventHandler<T> handler, object sender, T args) + { + if (handler != null) + { + Task.Run(() => + { + try + { + handler(sender, args); + } + catch (Exception ex) + { + Logger.LogException("Error in event handler", ex); + } + }); + } + } + + /// <summary> + /// Fires the event. + /// </summary> + /// <param name="handler">The handler.</param> + /// <param name="sender">The sender.</param> + /// <param name="args">The <see cref="EventArgs" /> instance containing the event data.</param> + 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); + } + } + } + + /// <summary> + /// Fires the event. + /// </summary> + /// <typeparam name="T"></typeparam> + /// <param name="handler">The handler.</param> + /// <param name="sender">The sender.</param> + /// <param name="args">The args.</param> + public static void FireEventIfNotNull<T>(EventHandler<T> handler, object sender, T args) + { + if (handler != null) + { + try + { + handler(sender, args); + } + catch (Exception ex) + { + Logger.LogException("Error in event handler", ex); + } + } + } + } +} diff --git a/MediaBrowser.Common/Events/GenericEventArgs.cs b/MediaBrowser.Common/Events/GenericEventArgs.cs index 98e072816f..e7cf524d45 100644 --- a/MediaBrowser.Common/Events/GenericEventArgs.cs +++ b/MediaBrowser.Common/Events/GenericEventArgs.cs @@ -1,12 +1,17 @@ -using System;
-
-namespace MediaBrowser.Common.Events
-{
- /// <summary>
- /// Provides a generic EventArgs subclass that can hold any kind of object
- /// </summary>
- public class GenericEventArgs<T> : EventArgs
- {
- public T Argument { get; set; }
- }
-}
+using System; + +namespace MediaBrowser.Common.Events +{ + /// <summary> + /// Provides a generic EventArgs subclass that can hold any kind of object + /// </summary> + /// <typeparam name="T"></typeparam> + public class GenericEventArgs<T> : EventArgs + { + /// <summary> + /// Gets or sets the argument. + /// </summary> + /// <value>The argument.</value> + public T Argument { get; set; } + } +} |
