Asynchronous Invocation by Bart De Smet

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

O'Reilly logo

Asynchronous Invocation

So far, you’ve seen delegates that return nearly instantaneously when they are being invoked. For example:

Func<int, int, int> add = (a, b) => a + b;int three = add(1, 2); // returns in nanoseconds

However, delegates can invoke long-running operations, too. If the method being referred to takes a long while to complete, the invocation site of the delegate will be blocked until the call returns. This is an important realization for APIs that accept as their input a delegate that gets called subsequently: The API can’t know how the call will perform given certain inputs. For example, in our calculator example, we could add the following custom function:

calc.AddOperator("F1", ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required