DevForce Help Reference
ConnectAsync(CancellationToken) Method
Example 


Connect to the IdeaBlade.EntityModel.Server.EntityServer asynchronously.
Syntax
'Declaration
 
Public Overloads Function ConnectAsync( _
   ByVal cancellationToken As CancellationToken _
) As Task
'Usage
 
Dim instance As EntityManager
Dim cancellationToken As CancellationToken
Dim value As Task
 
value = instance.ConnectAsync(cancellationToken)
public Task ConnectAsync( 
   CancellationToken cancellationToken
)

Parameters

cancellationToken
Exceptions
ExceptionDescription
EntityServerException Exception thrown by the EntityServer for persistence failures.
Remarks
Use ConnectAsync and Disconnect to manage the connection to the EntityServer. You should have an EntityServerError handler in place to catch connection failures.

In Silverlight applications, ConnectAsync is called implicitly when you construct an EntityManager with either the default constructor or a constructor with a true "shouldConnect" argument. In these cases, you may want to check the IsConnected property before issuing other requests.

Connect does not connect to any backend data sources.

Example
private bool Initialize() {
      string runTimeEnv;
#if TEST
      runTimeEnv = "Test";
#else
      runTimeEnv = "Prod";
#endif

      // Initialize an EntityManager for the given data source extension, and set up an error handler.
      IdeaBladeTest1Manager mgr = new IdeaBladeTest1Manager(false, runTimeEnv);
      mgr.EntityServerError += EntityServerErrorHandler;

      // Explicitly connect to the BOS now.
      // Note that no data source connection is made until entities are accessed.
      try {
        mgr.Connect();
      } catch (EntityServerException ese) {
        MessageBox.Show(ese.Message, "EntityServerException");
      } catch (Exception e) {
        MessageBox.Show(e.Message, "Exception");
      }
      return mgr.IsConnected;
    }
    private void EntityServerErrorHandler(object pSender, EntityServerErrorEventArgs e) {
      // Always a good idea to log all exception info.
      Exception ex = e.Exception;
      while (ex != null) {
        TraceFns.WriteLine(ex.ToString());
        ex = ex.InnerException;
      }
      MessageBox.Show("Trying to handle error");
      // Leave e.Handled = false if the Error should be thrown back to the calling code
      e.Handled = true;         // exception will not be thrown
    }
Requirements

Target Platforms: Windows 7, Windows Vista SP1 or later, Windows XP SP3, Windows Server 2008 (Server Core not supported), Windows Server 2008 R2 (Server Core supported with SP1 or later), Windows Server 2003 SP2

See Also

Reference

EntityManager Class
EntityManager Members
Overload List
Disconnect Method

Send Feedback