NGWS SDK Documentation  

This is preliminary documentation and subject to change.
To comment on this topic, please send us email at ngwssdk@microsoft.com. Thanks!

Asynchronous Programming Model Implementation Notes

Async calls via delegates

The implementation of the asynchronous methods on the delegate class will utilize the following infrastructure pieces to provide Async calls within the same appdomain and between appdomains (including between processes and machines):

Delegate BeginInvoke and EndInvoke methods

Compilers should emit delegate classes with Invoke, BeginInvoke and EndInvoke methods using the delegate signature specified by the user. The BeginInvoke and EndInvoke should be decorated as native. Since these methods are marked as native the implementation is automatically provided by the NGWS runtime at class load time. The loader ensures that they are not overridden.

Delegate Parameters

For example if we take the Factorizing delegate.

class FactorizingCallback : delegate
{
   public bool Invoke(
         int factorizableNum,  
         ref int primefactor1,
         ref int primefactor2);

   // Supplied by the compiler
   public IAsyncResult BeginInvoke(
         int factorizableNum,  
         ref int primefactor1,
         ref int primefactor2,
         AsyncCallback cb,
         Object AsyncObject
         );

   // Supplied by the compiler
   public bool EndInvoke(
         ref int primefactor1,
         ref int primefactor2,
         IAsyncResult ar);
}

BeginInvoke:

EndInvoke:

Cancel

Cancel is not provided on the IAsyncResult interface. Cancel is not provided on IAsyncResult since in many implementations there can be no guarentee’s on canceling the BeginXXX call. Exposing and implementing Canceling on an Async BeginXXXX call is up to the implementer of the class when exposes BeginXXXX and EndXXXX. They could choose to provide a CancelXXXX method.

Exceptions

BeginXXXX. If the BeginXXX method throws an exception, then the caller can assume that an asynchronous operation was not started and that the callback delegate will not be called. BeginXXX can throw infrastructure exceptions.

EndXXXX. Exceptions are returned from asynchronous operations by throwing them from the EndXXXX method. EndXXX can throw infrastructure and called object exceptions.

Delegates and Contexts

Delegates can also be bound to particular context. When the delegate is call it will route the call to the correct content.

class Delegate

{
    //. . .
    public void BindToContext ();
    //. . .
};