public
static void Main() {
SampSyncSqrDelegate sampleDelegate =
new
SampSyncSqrDelegate(sampSyncObj.Square);
IAsyncResult ar1 =
sampleDelegate.BeginInvoke (42,
new
AsyncCallback(AsyncResultSample.MyCallback), 42);
// … do useful work …
WaitHandle wh =
ar1.AsyncWaitHandle;
wh.WaitOne();
}
public
static void MyCallback(IAsyncResult ar) {
int
cookieValue = Convert.ToInt32(ar.AsyncState);
// … here, check cookieValue
to put result in the right place…
int result = ((SampSyncSqrDelegate)
((AsyncResult)ar).AsyncDelegate).EndInvoke(ar);
Console.WriteLine(“Result is {0}", result);
}
int main()
{
future<int> result = active
{ sampSyncObj.Square( 42 ) };
//
… do useful work …
Console.WriteLine(“Result is {0}",
result.wait());
}