using MediaBrowser.Model.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.ErrorException("Error in event handler", ex);
}
});
}
}
///
/// 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.ErrorException("Error in event handler", ex);
}
});
}
}
///
/// 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.ErrorException("Error in event handler", ex);
}
}
}
///
/// 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.ErrorException("Error in event handler", ex);
}
}
}
}
}