Asynchronous call with a result in C#
int Add(int a, int b) {
Thread.Sleep(3000);
return a + b;
}
//Invoked at the end of the delegate
void DelComplete(IAsyncResult result)
{
var aResult = (AsyncResult)result;
var delBinary = (DelBinary)aResult.AsyncDelegate;
var addResult = delBinary.EndInvoke(result);
//addResult is 8
}
delegate int DelBinary(int a, int b);
var delBinary = new DelBinary(Add);
//Asynchronous method call Add()
delBinary.BeginInvoke(5, 3, DelComplete, null);
- Log in to post comments