IdeaBlade DevForce 2010 Help Reference
ConnectAsync(Action<BaseOperation>,Object) Method
See Also  Example Send Feedback
IdeaBlade.EntityModel Assembly > IdeaBlade.EntityModel Namespace > EntityManager Class > ConnectAsync Method : ConnectAsync(Action<BaseOperation>,Object) Method



userCallback
Optional callback called when the operation completes
userState
Optional user token identifying the operation
Connect to the IdeaBlade.EntityModel.Server.EntityServer asynchronously.

Syntax

Visual Basic (Declaration) 
Public Overloads Function ConnectAsync( _
   ByVal userCallback As Action(Of BaseOperation), _
   Optional ByVal userState As Object _
) As BaseOperation
Visual Basic (Usage)Copy Code
Dim instance As EntityManager
Dim userCallback As Action(Of BaseOperation)
Dim userState As Object
Dim value As BaseOperation
 
value = instance.ConnectAsync(userCallback, userState)
C# 
public BaseOperation ConnectAsync( 
   Action<BaseOperation> userCallback,
   object userState
)
C++/CLI 
public:
BaseOperation^ ConnectAsync( 
   Action<BaseOperation^>^ userCallback,
   Object^ userState
) 

Parameters

userCallback
Optional callback called when the operation completes
userState
Optional user token identifying the operation

Exceptions

Example

C#Copy Code
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
    }

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.

Requirements

Target Platforms: Windows 98, Windows NT 4.0, Windows Millennium Edition, Windows 2000, Windows XP Home Edition, Windows XP Professional, Windows Server 2003 family, Windows Vista, Windows Server 2008 family

See Also

© 2013 All Rights Reserved.