using System;
using System.Threading.Tasks;
using Microsoft.Extensions.Logging;
namespace MediaBrowser.Common.Events
{
///
/// Class EventHelper.
///
// TODO: @bond Remove
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 is not null)
{
Task.Run(() =>
{
try
{
handler(sender, args);
}
catch (Exception ex)
{
logger.LogError(ex, "Error in event handler");
}
});
}
}
///
/// Queues the event.
///
/// Argument type for the handler.
/// The handler.
/// The sender.
/// The args.
/// The logger.
public static void QueueEventIfNotNull(EventHandler? handler, object sender, T args, ILogger logger)
{
if (handler is not null)
{
Task.Run(() =>
{
try
{
handler(sender, args);
}
catch (Exception ex)
{
logger.LogError(ex, "Error in event handler");
}
});
}
}
}
}