Exemplo n.º 1
0
        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);
        }
Exemplo n.º 2
0
        /// <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);
            }
        }
Exemplo n.º 3
0
        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);
            }
        }
Exemplo n.º 4
0
        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);
            }
        }
Exemplo n.º 5
0
        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);
            }
        }