public static void UnsafeFireInParallel(Delegate del, params object[] args) { if (args.Length > 7) { Trace.TraceWarning("Too many parameters. Consider a structure to enable the use of the type-safe versions"); } if (del == null) { return; } Delegate[] delegates = del.GetInvocationList(); List <WaitHandle> calls = new List <WaitHandle>(delegates.Length); AsyncFire asyncFire = InvokeDelegate; foreach (Delegate sink in delegates) { IAsyncResult asyncResult = asyncFire.BeginInvoke(sink, args, null, null); calls.Add(asyncResult.AsyncWaitHandle); } WaitHandle[] handles = calls.ToArray(); WaitHandle.WaitAll(handles); Action <WaitHandle> close = delegate(WaitHandle handle) { handle.Close(); }; Array.ForEach(handles, close); }
/// <summary> /// Fires the event delegate asynchronous. /// </summary> /// <param name="eventDelegate">The event delegate.</param> /// <param name="args">The arguments.</param> public static void FireAsync(Delegate eventDelegate, params object[] args) { Delegate temp = eventDelegate; if (temp == null) { return; } Delegate[] delegates = eventDelegate.GetInvocationList(); foreach (Delegate sink in delegates) { AsyncFire asyncFire = InvokeDelegate; asyncFire.BeginInvoke(sink, args, null, null); } }
public static void InvokeDelegateAsync(Delegate del, params object[] args) { if (del == null) { return; } AsyncCallback cleanUp = delegate(IAsyncResult asyncResult) { asyncResult.AsyncWaitHandle.Close(); }; AsyncFire asyncFire = new AsyncFire(InvokeDelegate); foreach (Delegate sink in del.GetInvocationList()) { asyncFire.BeginInvoke(sink, args, cleanUp, null); } }
public static void UnsafeFireAsync(Delegate del, params object[] args) { if (del == null) { return; } Delegate[] delegates = del.GetInvocationList(); AsyncFire asyncFire = InvokeDelegate; AsyncCallback cleanup = delegate(IAsyncResult asyncResult) { asyncResult.AsyncWaitHandle.Close(); }; foreach (Delegate sink in delegates) { asyncFire.BeginInvoke(sink, args, cleanup, null); } }
public static void UnsafeFireAsync(Delegate del, params object[] args) { if (args.Length > 7) { Trace.TraceWarning("Too many parameters. Consider a structure to enable the use of the type-safe versions"); } if (del == null) { return; } Delegate[] delegates = del.GetInvocationList(); AsyncFire asyncFire = InvokeDelegate; AsyncCallback cleanUp = delegate(IAsyncResult asyncResult) { asyncResult.AsyncWaitHandle.Close(); }; foreach (Delegate sink in delegates) { asyncFire.BeginInvoke(sink, args, cleanUp, null); } }