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); }
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(); }
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); }
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)); }
/// <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 { } }
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 { } }
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 { } }
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; } }
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); } }
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; } }
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 { } }
//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); }
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; } }
/// <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; } }
//广播中线程调用完成的回调方法 //功能:清除异常多路广播委托的调用列表中异常对象(空对象) 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; } }
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); }
/// <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; } }
// 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"); }
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); }
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); }
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); }