ComponentSpace Proxy Class Library Reference

ProxyClientBase.BeginConnect Method (String, Int32, String, String, Object)

Initiates an asynchronous connect operation that has a specified state object.

[Visual Basic]
NotOverridable Overloads Public Function BeginConnect( _
   ByVal serverAddress As String, _
   ByVal serverPort As Integer, _
   ByVal userName As String, _
   ByVal password As String, _
   ByVal stateObject As Object _
) As IAsyncResult _
    Implements IProxyClient.BeginConnect
[C#]
public IAsyncResult BeginConnect(
   string serverAddress,
   int serverPort,
   string userName,
   string password,
   object stateObject
);

Parameters

serverAddress
The destination server address (eg. 66.210.153.11 or www.myserver.com).
serverPort
The destination server port number.
userName
The user name or null.
password
The password or null.
stateObject
A state object, specified by the application, that contains information associated with the asynchronous operation.

Return Value

The IAsyncResult that identifies the posted asynchronous request.

Implements

IProxyClient.BeginConnect

Remarks

In asynchronous processing, you use BeginConnect to raise the ConnectCompleted event when the connect operation has completed.

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.

To use BeginConnect, create an event handler that processes the results of the asynchronous operation and associate it with your event delegate. BeginConnect initiates an asynchronous connect operation; the ProxyClientBase is notified, through the raising of the ConnectCompleted event, when the connect operation is completed. The ProxyClientBase can then access the connect status by calling EndConnect.

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

Because BeginConnect is asynchronous, you can call it to receive the connect status without blocking the current thread of execution. To synchronously connect, use the Connect method.

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

The IAsyncResult that BeginConnect 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 EndConnect 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 BeginConnect 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

ProxyClientBase Class | ComponentSpace.Proxy Namespace | ProxyClientBase.BeginConnect Overload List