Use a Callback with an Asynchronous Call

Problem

You want to be notified as soon as an asynchronous call completes, without needing to poll the IAsyncResult object.

Solution

Use a callback, which will be triggered automatically when the call completes.

Discussion

Often, when you start a multithreaded task in an application, you don’t want the additional complexity and overhead of monitoring that task. The solution is to use a callback. With a callback, your code executes a function or subroutine asynchronously and carries on with other work. Your callback procedure is automatically invoked when the asynchronous call is finished.

The callback approach allows you to separate the code that processes asynchronous tasks from the code that performs work on ...

Get Microsoft® Visual Basic® .NET Programmer's Cookbook now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.