learn.microsoft.com/en-us/dotnet/standard/asynchronous-programming-patterns/using-an-asynccallback-delegate-and-state-object
1 Users
0 Comments
34 Highlights
0 Notes
Tags
Top Highlights
request
Dns.EndGetHostEntry
When you use an AsyncCallback delegate to process the results of the asynchronous operation in a separate thread, you can use a state object to pass information between the callbacks and to retrieve a final result.
AsyncCallback Delegate
State Object
demonstrates using asynchronous methods in the Dns class to retrieve Domain Name System (DNS) information for user-specified computers.
uses the HostRequest class to store state information.
A HostRequest object gets created for each computer name entered by the user.
This object is passed to the BeginGetHostByName method.
The ProcessDnsInformation method is called each time a request completes.
The HostRequest object is retrieved using the AsyncState property.
The ProcessDnsInformation method uses the HostRequest object to store the IPHostEntry returned by the request or a SocketException thrown by the request.
HostRequest
a state object that holds each requested host name,
an associated IPHostEntry object or a SocketException.
hostName
SocketException e
IPHostEntry entry
AsyncCallback callBack = new AsyncCallback(ProcessDnsInformation);
HostRequest request = new HostRequest(host);
Glasp is a social web highlighter that people can highlight and organize quotes and thoughts from the web, and access other like-minded people’s learning.