public void GetResultsOnCallback(IAsyncResult ar) { GetAddressDelegate del = (GetAddressDelegate) ((AsyncResult)ar).AsyncDelegate; try { string result; result = del.EndInvoke(ar); Console.WriteLine("\nOn CallBack: result is " + result); } catch (Exception ex) { Console.WriteLine("\nOn CallBack, problem occurred: " + ex.Message); } }
public void GetAddressAsyncWait(string name) { GetAddressDelegate dc = new GetAddressDelegate(this.GetAddress); IAsyncResult ar = dc.BeginInvoke(name, null, null); // Main thread can in principle do other work now try { string result = dc.EndInvoke(ar); Console.WriteLine("\nAsync waiting : " + result); } catch (Exception ex) { Console.WriteLine("\nAsync waiting, a problem occurred : " + ex.Message); } }
public void GetResultsOnCallback(IAsyncResult ar) { GetAddressDelegate del = (GetAddressDelegate)((AsyncResult)ar).AsyncDelegate; try { string result; result = del.EndInvoke(ar); lock (this) { this.address = result; this.status = ResultStatus.Done; } } catch (Exception ex) { lock (this) { this.address = ex.Message; this.status = ResultStatus.Failed; } } }