Ejemplo n.º 1
0
 /// <summary>
 /// AsyncInvoke in another thread
 /// </summary>
 /// <param name="invoker">invoker delegate</param>
 /// <param name="callback">callback delegate </param>
 public void AsyncInvoke <T> (AsyncInvokeDelegate <T> invoker, AsyncCallbackDelegate <T> callback)
 {
     ThreadPool.QueueUserWorkItem(new WaitCallback(delegate(object state) {
         AsyncCallback <T> result;
         try {
             T invoke = invoker();
             result   = new AsyncCallback <T> (invoke);
             callback(result);
         } catch (Exception ex) {
             result = new AsyncCallback <T> (ex, false);
             callback(result);
         }
     }));
 }
Ejemplo n.º 2
0
        public static void CallAsyncMethod(Delegate eventDelegate, params object[] args)
        {
            if (eventDelegate != null)
            {
                Delegate[] delegates = eventDelegate.GetInvocationList();

                AsyncInvokeDelegate invoker = new AsyncInvokeDelegate(InvokeDelegate);

                AsyncCallback cleanUp = new AsyncCallback(AsyncDelegateCleanup);

                foreach (Delegate sink in delegates)
                {
                    invoker.BeginInvoke(sink, args, cleanUp, null);
                }
            }
        }
Ejemplo n.º 3
0
        public static void CallAsyncMethod(Delegate eventDelegate, params object[] args)
        {
            if (eventDelegate != null)
            {
                Delegate[] delegates = eventDelegate.GetInvocationList();

                AsyncInvokeDelegate invoker = new AsyncInvokeDelegate(InvokeDelegate);

                AsyncCallback cleanUp = new AsyncCallback(AsyncDelegateCleanup);

                foreach (Delegate sink in delegates)
                {
                    invoker.BeginInvoke(sink, args, cleanUp, null);
                }
            }
        }
Ejemplo n.º 4
0
        public static void FireAsyncEvent(Delegate eventDelegate, object sender, EventArgs args)
        {
            if (eventDelegate != null)
            {
                object[] argsObj = new object[2];

                argsObj[0] = sender;
                argsObj[1] = args;

                Delegate[] delegates = eventDelegate.GetInvocationList();

                AsyncInvokeDelegate invoker = new AsyncInvokeDelegate(InvokeDelegate);

                AsyncCallback cleanUp = new AsyncCallback(AsyncDelegateCleanup);

                foreach (Delegate sink in delegates)
                {
                    invoker.BeginInvoke(sink, argsObj, cleanUp, null);
                }
            }
        }
Ejemplo n.º 5
0
        public static void FireAsyncEvent(Delegate eventDelegate, object sender, EventArgs args)
        {
            if (eventDelegate != null)
            {
                object[] argsObj = new object[2];

                argsObj[0] = sender;
                argsObj[1] = args;

                Delegate[] delegates = eventDelegate.GetInvocationList();

                AsyncInvokeDelegate invoker = new AsyncInvokeDelegate(InvokeDelegate);

                AsyncCallback cleanUp = new AsyncCallback(AsyncDelegateCleanup);

                foreach (Delegate sink in delegates)
                {
                    invoker.BeginInvoke(sink, argsObj, cleanUp, null);
                }
            }
        }