Skip to content

Instantly share code, notes, and snippets.

@aturgarg
Created July 27, 2011 12:47
Show Gist options
  • Select an option

  • Save aturgarg/1109292 to your computer and use it in GitHub Desktop.

Select an option

Save aturgarg/1109292 to your computer and use it in GitHub Desktop.
Using Asynchronous function calls
//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