Created
July 27, 2011 12:47
-
-
Save aturgarg/1109292 to your computer and use it in GitHub Desktop.
Using Asynchronous function calls
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| //Asynchronous | |
| //--------------- | |
| public string MainFunction(Context aCtx) | |
| { | |
| CallProcessingMethod(aCtx); | |
| } | |
| public delegate string DelegateProcessing(Context aCtx); | |
| private void CallProcessingMethod(Context aCtx) | |
| { | |
| // create the delegate | |
| DelegateProcessing delProcessing = new DelegateProcessing(ProcessingMethod); | |
| delProcessing.BeginInvoke(aCtx, new AsyncCallback(CallBackProcessing), null); | |
| } | |
| private void CallBackProcessing(IAsyncResult ar) | |
| { | |
| // first case IAsyncResult to an AsyncResult object, so we can get the | |
| // delegate that was used to call the function. | |
| AsyncResult asyncResult = (AsyncResult)ar; | |
| // grab the delegate | |
| DelegateProcessing del = (DelegateProcessing)asyncResult.AsyncDelegate; | |
| // now that we have the delegate, | |
| // we must call EndInvoke on it, so we can get all | |
| // the information about our method call. | |
| try | |
| { | |
| del.EndInvoke(ar); | |
| } | |
| catch { } | |
| } | |
| private string ProcessingMethod(Context aCtx) | |
| { | |
| return ""; | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment