ComponentSpace DNS Class Library Reference

DnsClient.BeginSend Method (DnsMessage, Object, AsyncCallback)

Initiates an asynchronous send operation that has a specified state object. This overload receives notification, through a callback, of the identity of the event handler for this operation.

[Visual Basic]
Overloads Public Function BeginSend( _
   ByVal dnsMessage As DnsMessage, _
   ByVal stateObject As Object, _
   ByVal asyncCallback As AsyncCallback _
) As IAsyncResult
[C#]
public IAsyncResult BeginSend(
   DnsMessage dnsMessage,
   object stateObject,
   AsyncCallback asyncCallback
);

Parameters

dnsMessage
The DNS request message to send.
stateObject
A state object, specified by the application, that contains information associated with the asynchronous operation.
asyncCallback
The AsyncCallback that will receive the notification of the asynchronous operation completion.

Return Value

The IAsyncResult that identifies the posted asynchronous request.

Remarks

When you use this overload, the callback specified in the callback parameter is invoked directly when the send operation has completed; the SendCompleted event is not raised. The other overloads of BeginSend rely on this component to raise the SendCompleted event.

To use BeginSend, define an asynchronous callback method. BeginSend initiates an asynchronous send operation; the DnsClient is notified, through a call to the callback method, when the send operation is completed. The DnsClient can then access the send status by calling EndSend.

Use this overload to associate information with the operation that will be preserved throughout the operation's lifetime. The event handler can detect this information by looking at the AsyncState of the IAsyncResult that is associated with the operation.

Note: The BeginSend method returns immediately, but the asynchronous operation is not completed until the event handler is called.

Because BeginSend is asynchronous, you can call it to receive the send status without blocking the current thread of execution. To synchronously send, use the Send method.

Once an asynchronous operation completes, you can call BeginSend again in the event handler to keep receiving notifications.

The IAsyncResult that BeginSend returns identifies the asynchronous operation that the method call started. You can use this IAsyncResult throughout the lifetime of the operation, although you generally do not use it until EndSend is called. However, if you start several asynchronous operations, you can place their IAsyncResult values in an array and specify whether to wait for all operations or any operation to complete. In this case, you use the AsyncWaitHandle property of the IAsyncResult to identify the completed operation.

The state object associates state information with the operation. For example, if you call BeginSend multiple times to initiate multiple operations, you can identify each operation through a separate state object that you define.

You can also use the state object to pass information across process threads. If a thread is started but the callback is on a different thread in an asynchronous scenario, the state object is marshaled and passed back along with information from the event.

See Also

DnsClient Class | ComponentSpace.Dns Namespace | DnsClient.BeginSend Overload List