예제 #1
0
        void ReportCompletion(IAsyncResult asyncResult)
        {
            System.Runtime.Remoting.Messaging.AsyncResult ar = (System.Runtime.Remoting.Messaging.AsyncResult)asyncResult;

            DoWorkEventHandler del;

            del = (DoWorkEventHandler)ar.AsyncDelegate;

            DoWorkProviderEventArgs doWorkArgs = (DoWorkProviderEventArgs)ar.AsyncState;

            object result = null;

            Exception error = null;

            try
            {
                del.EndInvoke(asyncResult);

                result = doWorkArgs.Result;
            }

            catch (Exception exception)
            {
                error = exception;
            }

            RunWorkerCompletedProviderEventArgs completedArgs = new RunWorkerCompletedProviderEventArgs(result, error, doWorkArgs.Cancel);

            OnRunWorkerCompleted(completedArgs);
        }
예제 #2
0
        static void BackupComplete(IAsyncResult ar)
        {
            System.Runtime.Remoting.Messaging.AsyncResult iar = (System.Runtime.Remoting.Messaging.AsyncResult)ar;
            delDatabaseBackup state = (delDatabaseBackup)iar.AsyncDelegate;

            bDatabaseBackup = state.EndInvoke(ar);
            ar.AsyncWaitHandle.Close();
        }
예제 #3
0
        private void AsyncComplete(IAsyncResult result)
        {
            System.Runtime.Remoting.Messaging.AsyncResult asyncResult = (System.Runtime.Remoting.Messaging.AsyncResult)result;
            ((Action <string>)asyncResult.AsyncDelegate).EndInvoke(result);


            Console.WriteLine("AsyncComplete I'm on {0}", Thread.CurrentThread.ManagedThreadId);
            Console.WriteLine(result.AsyncState);
        }
예제 #4
0
            public static void EndUpEvent(IAsyncResult iar)
            {
                System.Runtime.Remoting.Messaging.AsyncResult ar = (System.Runtime.Remoting.Messaging.AsyncResult)iar;
                object         o             = ar.AsyncDelegate;
                UpEventHandler invokedMethod = (UpEventHandler)ar.AsyncDelegate;

                try { invokedMethod.EndInvoke(iar); }
                catch { }
            }
        protected override IInputSessionChannel OnEndAcceptChannel(IAsyncResult result)
        {
            System.Runtime.Remoting.Messaging.AsyncResult aresult = result as System.Runtime.Remoting.Messaging.AsyncResult;
            if (aresult == null)
            {
                throw new ArgumentException("Invalid IAsyncResult type");
            }
            AcceptChannelDelegate d = aresult.AsyncDelegate as AcceptChannelDelegate;

            return(d.EndInvoke(result));
        }
예제 #6
0
 /// <summary>
 /// Asynchronous callback method
 /// </summary>
 /// <param name="param">Result</param>
 private void AsyncCallback(IAsyncResult param)
 {
     System.Runtime.Remoting.Messaging.AsyncResult result = (System.Runtime.Remoting.Messaging.AsyncResult)param;
     if (result.AsyncDelegate is ActionTriggerEventHandler)
     {
         ((ActionTriggerEventHandler)result.AsyncDelegate).EndInvoke(result);
     }
     else
     {
     }
 }
예제 #7
0
        private static void StartCallback(IAsyncResult ar)
        {
            System.Runtime.Remoting.Messaging.AsyncResult result = (System.Runtime.Remoting.Messaging.AsyncResult)ar;
            Action <string> del = (Action <string>)result.AsyncDelegate;

            try
            {
                del.EndInvoke(ar);
            }
            catch { }
        }
예제 #8
0
 private void AsyncCallback(IAsyncResult ar)
 {
     try
     {
         System.Runtime.Remoting.Messaging.AsyncResult result = (System.Runtime.Remoting.Messaging.AsyncResult)ar;
         AsyncMethodCaller caller = (AsyncMethodCaller)result.AsyncDelegate;
         caller.EndInvoke(ar);
     }
     catch (Exception e)
     {
         throw new System.Exception("SendingError");
     }
 }
        private void EndAsync(IAsyncResult ar)
        {
            Chat d = null;

            try
            {
                System.Runtime.Remoting.Messaging.AsyncResult asres = (System.Runtime.Remoting.Messaging.AsyncResult)ar;
                d = ((Chat)asres.AsyncDelegate);
                d.EndInvoke(ar);
            }
            catch
            {
            }
        }
예제 #10
0
        private void EndAsync(IAsyncResult ar)
        {
            ChatEventHandler d = null;

            try
            {
                System.Runtime.Remoting.Messaging.AsyncResult asres = (System.Runtime.Remoting.Messaging.AsyncResult)ar;
                d = ((ChatEventHandler)asres.AsyncDelegate);
                d.EndInvoke(ar);
            }
            catch
            {
                broadcastList -= d;
            }
        }
예제 #11
0
        private void EndAsyncManager(IAsyncResult ar)
        {
            AiMsgDel d = null;

            try
            {
                System.Runtime.Remoting.Messaging.AsyncResult asres = (System.Runtime.Remoting.Messaging.AsyncResult)ar;
                d = ((AiMsgDel)asres.AsyncDelegate);
                d.EndInvoke(ar);
            }
            catch
            {
                DeviceList.Remove(MyDeviceDel);
            }
        }
예제 #12
0
        private void EndAsync(IAsyncResult ar)
        {
            Data d = null;

            try
            {
                System.Runtime.Remoting.Messaging.AsyncResult asres = (System.Runtime.Remoting.Messaging.AsyncResult)ar;
                d = ((Data)asres.AsyncDelegate);
                d.EndInvoke(ar);
            }
            catch
            {
                List -= d;
            }
        }
예제 #13
0
        private void Completed(IAsyncResult result)
        {
            System.Runtime.Remoting.Messaging.AsyncResult asyncResult = result as System.Runtime.Remoting.Messaging.AsyncResult;
            MyFunctionDelegate myDelegate   = (MyFunctionDelegate)asyncResult.AsyncDelegate;
            DialogResult       dialogResult = myDelegate.EndInvoke(asyncResult);

            if (dialogResult == DialogResult.OK)
            {
                MessageBox.Show("OK!");
            }
            else
            {
                MessageBox.Show("Cancelled!");
            }
        }
 /// <summary>
 /// Asynchronous callback method
 /// </summary>
 /// <param name="param">Result</param>
 private void AsyncCallback(IAsyncResult param)
 {
     System.Runtime.Remoting.Messaging.AsyncResult result = (System.Runtime.Remoting.Messaging.AsyncResult)param;
     if (result.AsyncDelegate is NewMessengerEventHandler)
     {
         ((NewMessengerEventHandler)result.AsyncDelegate).EndInvoke(result);
     }
     else if (result.AsyncDelegate is UpdateMessengerEventHandler)
     {
         ((UpdateMessengerEventHandler)result.AsyncDelegate).EndInvoke(result);
     }
     else
     {
     }
 }
예제 #15
0
        //Target of AsyncCallback delegate should match the following pattern
        public static void AddComplete(System.IAsyncResult iftAr)
        {
            System.Console.WriteLine("AddComplete() running on thread {0}", System.Threading.Thread.CurrentThread.ManagedThreadId);
            System.Console.WriteLine("Operation completed.");

            //Getting result
            System.Runtime.Remoting.Messaging.AsyncResult ar = (System.Runtime.Remoting.Messaging.AsyncResult)iftAr;
            BinaryOp bp     = (BinaryOp)ar.AsyncDelegate;
            int      result = bp.EndInvoke(iftAr);

            //Recieving the message from Main() thread.
            string msg = (string)iftAr.AsyncState;

            System.Console.WriteLine("5 + 5 ={0}", result);
            System.Console.WriteLine("Message recieved on thread {0}: {1}", System.Threading.Thread.CurrentThread.ManagedThreadId, msg);
        }
예제 #16
0
        private static void BroadcastMessageCallback(IAsyncResult result)
        {
            DebugEventHandler asyncDelegate = null;

            try
            {
                System.Runtime.Remoting.Messaging.AsyncResult asyncResult = (System.Runtime.Remoting.Messaging.AsyncResult)result;

                asyncDelegate = ((DebugEventHandler)asyncResult.AsyncDelegate);

                asyncDelegate.EndInvoke(result);
            }
            catch
            {
                DebugEvent -= asyncDelegate;
            }
        }
예제 #17
0
        /// <summary>
        /// Is called as a callback from the asynchronous call, so simply get the
        /// delegate and do an EndInvoke on it, to signal the asynchronous call is
        /// now completed
        /// </summary>
        /// <param name="ar">The asnch result</param>
        private void EndAsync(IAsyncResult ar)
        {
            ChatEventHandler d = null;

            try
            {
                //get the standard System.Runtime.Remoting.Messaging.AsyncResult,and then
                //cast it to the correct delegate type, and do an end invoke
                System.Runtime.Remoting.Messaging.AsyncResult asres = (System.Runtime.Remoting.Messaging.AsyncResult)ar;
                d = ((ChatEventHandler)asres.AsyncDelegate);
                d.EndInvoke(ar);
            }
            catch
            {
                ChatEvent -= d;
            }
        }
예제 #18
0
        //广播中线程调用完成的回调方法
        //功能:清除异常多路广播委托的调用列表中异常对象(空对象)
        private void EndAsync(IAsyncResult ar)
        {
            ChatEventHandler d = null;

            try
            {
                //封装异步委托上的异步操作结果
                System.Runtime.Remoting.Messaging.AsyncResult asres = (System.Runtime.Remoting.Messaging.AsyncResult)ar;
                //asres.AsyncDelegate 获取在异步调用asres 的委托对象,asres 来自对ar 的AsyncResult 封装,ar 来自线程异步调用的操作状态
                d = ((ChatEventHandler)asres.AsyncDelegate);
                //EndInvoke 返回由异步操作ar 生成的结果Object
                d.EndInvoke(ar);
            }
            catch
            {
                ChatEvent -= d;
            }
        }
예제 #19
0
        private void ReportCompletion(IAsyncResult asyncResult)
        {
            System.Runtime.Remoting.Messaging.AsyncResult ar = asyncResult as System.Runtime.Remoting.Messaging.AsyncResult;
            DoWorkEventHandler del        = ar.AsyncDelegate as DoWorkEventHandler;
            DoWorkEventArgsBw  doWorkArgs = (DoWorkEventArgsBw)ar.AsyncState;
            object             result     = null;
            Exception          error      = null;

            try {
                del.EndInvoke(asyncResult);
                result = doWorkArgs.Result;
            } catch (Exception exception) {
                error = exception;
            }

            RunWorkerCompletedEventArgsBw completedArgs = new RunWorkerCompletedEventArgsBw(result, error, doWorkArgs.Cancel);

            OnRunWorkerCompleted(completedArgs);
        }
예제 #20
0
파일: MainFrm.cs 프로젝트: KeliBox/CK_Sync
        /// <summary>
        /// 异步CallBack
        /// </summary>
        /// <param name="ar"></param>
        private void RunCallBack(IAsyncResult ar)
        {
            SyncEventHandler d = null;

            try
            {
                System.Runtime.Remoting.Messaging.AsyncResult asres = (System.Runtime.Remoting.Messaging.AsyncResult)ar;
                d = ((SyncEventHandler)asres.AsyncDelegate);
                d.EndInvoke(ar);

                frmSyn.BeginInvoke((Action) delegate()
                {
                    frmSyn.Close();
                });
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
예제 #21
0
 // This function is called after fulfillment of the scan device
 static private void InitDeviceResult(IAsyncResult iftAr)
 {
     try
     {
         System.Runtime.Remoting.Messaging.AsyncResult ar = (System.Runtime.Remoting.Messaging.AsyncResult)iftAr;
         Debug.WriteLine("scanning device begin");
         DelegateInitDevice bp = (DelegateInitDevice)ar.AsyncDelegate;
         ScanResultError = bp.EndInvoke(iftAr);
     }
     catch (Exception e)
     {
         Debug.WriteLine("scanning device error " + e.Message);
         ScanResultError = 1;
         Mode            = MODE.NotActive;
     }
     if (ScanResultError != 0)
     {
         stateTimer.Enabled = false;
         MessageBox.Show("Ошибка при обращении к устройству. Для выяснения деталей обратитесь к log файлу. ", "Error", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
     }
     Debug.WriteLine("scanning device end");
 }
예제 #22
0
        public void AsyncCallCompleted(IAsyncResult ar)
        {
            Console.WriteLine("AsyncCallCompleted执行线程ID:{0}", Thread.CurrentThread.ManagedThreadId);

            //获取委托对象
            System.Runtime.Remoting.Messaging.AsyncResult result = (System.Runtime.Remoting.Messaging.AsyncResult)ar;
            AsyncDelegate asyncDel = (AsyncDelegate)result.AsyncDelegate;

            //获取BeginInvoke传入的的state参数
            string strState = (string)ar.AsyncState;

            Console.WriteLine("传入的字符串是{0}", strState);

            //结束异步调用
            int    nThreadID;
            string strResult = asyncDel.EndInvoke(out nThreadID, ar);

            this.BeginInvoke(_delegate, new object[] { nThreadID.ToString() });

            Console.WriteLine("\nThe call executed on thread {0}, with return value \"{1}\".",
                              nThreadID, strResult);
        }
예제 #23
0
        void AsyncQueryCallback(IAsyncResult result)
        {
            TypedAsyncResult <string[][]> queryResult = (TypedAsyncResult <string[][]>)result.AsyncState;

            System.Runtime.Remoting.Messaging.AsyncResult delegateAsyncResult = (System.Runtime.Remoting.Messaging.AsyncResult)result;
            RunQueryDelegate runQueryDelegate = (RunQueryDelegate)delegateAsyncResult.AsyncDelegate;

            string[][] values            = null;
            Exception  originalException = null;

            try
            {
                values = runQueryDelegate.EndInvoke(result);
            }
            /* We don't want exceptions to be thrown from the callback method as these need to be made available to the thread that calls EndExecuteQuery. */
            catch (Exception e)
            {
                originalException = e;
            }

            /* Any exception is stored in query Result and re-thrown when EndExecuteQueryMethod calls TypedAsyncResult<string[][]>.End(..) method. */
            queryResult.Complete(values, false, originalException);
        }
예제 #24
0
 static void delCallBack(IAsyncResult async)
 {
     System.Runtime.Remoting.Messaging.AsyncResult ar = (System.Runtime.Remoting.Messaging.AsyncResult)async;
     jsonDelegate del = (jsonDelegate)ar.AsyncDelegate;
     JObject      ja  = del.EndInvoke(async);
 }