private void FuncCallback(IAsyncResult result) { Console.WriteLine("FuncCallback thread: {0}", Thread.CurrentThread.ManagedThreadId); var deleg = (Func <MethodInfo, object[], object>)((AsyncResult)result).AsyncDelegate; var state = result.AsyncState as GenericAsyncState; if (null != deleg) { Exception error = null; object retval = null; try { retval = deleg.EndInvoke(result); } catch (Exception e) { error = e; } var userState = state == null ? null : state.UserState; var methodName = state == null ? null : state.MethodName; var inValues = state == null ? null : state.InValues; var args = new GenericAsyncCompletedEventArgs(retval, error, methodName, userState, inValues); if (this.AsyncCompleted != null) { this.AsyncCompleted(this, args); } } }
void client1_AsynchCompleted(object sender, GenericAsyncCompletedEventArgs e) { Console.WriteLine("AsynchCompleted thread: {0}", Thread.CurrentThread.ManagedThreadId); Console.WriteLine("method: {0}", e.MethodName); var retval = e.Result as NameEntity; if (retval != null) { Console.WriteLine("AsyncCompleted {0}", retval._name); } if (client != null) { client.Dispose(); } }