delegate string LongRunningTask(CancellationToken ct);
static void MainMethod() {
CancellationToken ct = tokenSource2.Token;
// Instantiate delegates with LongRunningTask's signature:
LongRunningTask task1 = LongRunningProcess(ct);
// Start the invocation
IAsyncResult cookie = task1.BeginInvoke (ct, null, null);
// Can do something else here if needed (PerformOtherTask())
// PerformOtherTask();
// Get the results of the LongRunningProcess, waiting for completion if necessary.
// Here is where any exceptions will be thrown:
try
{
string s1 = task1.EndInvoke (cookie);
}
catch(Exception e)
{
throw;
}
}
|