using System;
using System.Threading;
using System.Threading.Tasks;

namespace SIASUN.Autopilot.EventMessage
{
    public static class EventArgsExtensions
    {
        public static void Raise<TEventArgs>(this TEventArgs e,
           Object sender, ref EventHandler<TEventArgs> eventDelegate)
        {
            EventHandler<TEventArgs> temp = Volatile.Read(ref eventDelegate);

            if (temp != null)
            {
                Task.Run(()=> { temp(sender, e); });
            }
        }
    }
}
