IConnection.ConnectAsync Method

The ConnectAsync method is used to establish a connection to the runtime system through an asynchronous call that does not block the client application calling it. When the connection is established, a specified callback handler is triggered to process the connection result.

Namespace – ABSuite.AccessLayer.Connector.Core

Assembly – Unisys.ABSuite.AccessLayer.Connector.Core (in Unisys.ABSuite.AccessLayer.Connector.Core.dll)

Syntax

Task<TransmissionObject> ConnectAsync(
 ConnectionDetails details,
   ATTConnectionDetails attDetails
)

Arguments

Return Value

This method executes an awaitable task and returns a TransmissionObject instance that specifies the current context of the system.

Using the IConnection Interface for the ConnectAsync Method

The following code shows an example of using the ConnectAsync() method to perform an asynchronous connection to the host system:

// Async Method to establish a host connection.
        public async void EstablishHostSessionAsync()
        {
            // Create a new connection to the AB Suite host system
            // Use the Access Layer API ConnectionFactory to create 
           // an instance of a Connection class
                ABSConnection = ConnectionFactory.Create();
    // Set up the ConnectionDetails object with the required entries
            ConnectionDetails cDetails = new ConnectionDetails()
            {
                Host = “localhost”, // Host name or IP Address
                System = “Sample”,  // Name of the Runtime System
                IsAnonymous = true, // Set anonymous access if   required
        AssemblyLocation = @"C:\ABSuite\Datamodels" // Sets the location of DataModels Assembly                
            };
      // Perform the ConnectAsync call using the defined connection details.
      // No ATT recording is required. Therefore, the second parameter 
      // is set to null.
      // We can await the ConnectAsync Task that lets the calling 
      // thread to continue processing. It returns an instance of the 
      // TransmissionObject. 
TransmissionObject trObj = null;
trObj = await ABSConnection.ConnectAsync(cDetails, null);
ApplicationLogger.LogInfo(() => string.Format("<Test Client>:: After Connect call!!"));
if (trObj != null && (trObj.State == TransmissionReturnCode.Ok || 
trObj.State == TransmissionReturnCode.OkWithSwitch))
 {
     CurrentIspecName = trObj.ObjectClassName;
     CurrentTO = trObj;
 }
     SessionConnected = true;     
}