Using an AsyncCallback Delegate to End an Asynchronous Operation
Applications that can do other work while waiting for the results of an asynchronous operation should not block waiting until the operation completes. Use one of the following options to continue executing instructions while waiting for an asynchronous operation to complete:
Use an AsyncCallback delegate to process the results of the asynchronous operation in a separate thread. This approach is demonstrated in this topic.
Use the IsCompleted property of the IAsyncResult returned by the asynchronous operation's BeginOperationName method to determine whether the operation has completed. For an example that demonstrates this approach, see Polling for the Status of an Asynchronous Operation.
The following code example demonstrates using asynchronous methods in the Dns class to retrieve Domain Name System (DNS) information for user-specified computers. This example creates an AsyncCallback delegate that references the ProcessDnsInformation method. This method is called once for each asynchronous request for DNS information.
Note that the user-specified host is passed to the BeginGetHostByName Object parameter. For an example that demonstrates defining and using a more complex state object, see Using an AsyncCallback Delegate and State Object.