DevForce Help Reference
InvokeServerMethodAsync(EntityManager,InvokeServerMethodArgs,Action<InvokeServerMethodOperation>,Object) Method
Example 


An instance of IdeaBlade.EntityModel.InvokeServerMethodArgs
Callback called when the operation completes
Token identifying the asynchronous request
Asynchronously invokes the specified static (Shared in Visual Basic) method for execution on the server.
Syntax
'Declaration
 
<ExtensionAttribute()>
Public Overloads Shared Function InvokeServerMethodAsync( _
   ByVal em As EntityManager, _
   ByVal args As InvokeServerMethodArgs, _
   ByVal userCallback As Action(Of InvokeServerMethodOperation), _
   ByVal userState As Object _
) As InvokeServerMethodOperation
'Usage
 
Dim em As EntityManager
Dim args As InvokeServerMethodArgs
Dim userCallback As Action(Of InvokeServerMethodOperation)
Dim userState As Object
Dim value As InvokeServerMethodOperation
 
value = EntityManagerAsyncExtensions.InvokeServerMethodAsync(em, args, userCallback, userState)

Parameters

em
args
An instance of IdeaBlade.EntityModel.InvokeServerMethodArgs
userCallback
Callback called when the operation completes
userState
Token identifying the asynchronous request
Exceptions
ExceptionDescription
System.ArgumentExceptionType name must be fully qualified
System.ArgumentExceptionUserState token must be unique for the client
System.Security.SecurityExceptionThe exception that is thrown when a security error is detected.
Remarks
The method called must be marked with the IdeaBlade.EntityModel.AllowRpcAttribute and correspond to the IdeaBlade.EntityModel.ServerMethodDelegate signature.

InvokeServerMethodAsync enables a client-side caller to invoke an arbitrary static method on the server using an asynchronous call. The data returned from the server method will be available in the IdeaBlade.EntityModel.InvokeServerMethodEventArgs passed to the callback provided.

Example
// Sample showing asynchronous invocation of server method

// In client class:
private void MakeAsyncCall() {
  EntityManager mgr = new DomainModelEntityManager();
  // Make async call
  Guid myToken = Guid.NewGuid();
  mgr.InvokeServerMethodAsync(new ServerMethodDelegate(Order.GetNumberOfOrdersSlow), 
      InvokeServerMethodAsyncCompleted, myToken, 
 	    new DateTime(1995, 1, 1), new DateTime(1999, 1, 1));
}
private void InvokeServerMethodAsyncCompleted(InvokeServerMethodOperation e) {
  Guid token = (Guid)e.UserState;
  if (!e.Cancelled) {
     MessageBox.Show("my async result = " + Convert.ToInt32(e.Result).ToString());
  }
}

// Sample method defined in Order entity class:
public class Order {
//...

  // ServerMethodDelegate method, called from client
  [AllowRpc]
  public static Object GetNumberOfOrdersSlow(IPrincipal pPrincipal, EntityManager pMgr, params Object[] pArgs) {
     // Sleep to make this slower to show async
     System.Threading.Thread.Sleep(2000);
     DateTime dt1 = pArgs[0] as DateTime;
     DateTime dt2 = pArgs[1] as DateTime;
     return pMgr.Order.Where(o => o.OrderDate >= dt1 && o.OrderDate <= dt2).Count();
  }
}
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

EntityManagerAsyncExtensions Class
EntityManagerAsyncExtensions Members
Overload List

Send Feedback