How to call async methods of C# custom library from Aras server methods?


We have some C# code written using async and await pattern, bu how can we call this async methods from Aras server methods? I tried using await, but doesnot compiles.

like,  var result = await myClassObj.SomeAsyncMethod();



  • Hi Vinay,

    I am also interested in this use case. I once found this sample from Chris but was not able to get it running:

  • Hi Vinay,

    This is not easily possible inside of a server method. One of the requirements for using asynchronous code inside of C# is that the containing method of your code needs to be using the async keyword.

    You can check out my response to this forum post for a brief explanation of how the code inside of your Method items gets compiled, but in shorter terms, your C# code basically gets plugged into another method before it gets compiled. This other method that your code gets inserted into does not use the async keyword, so you will not be able to take advantage of asynchronous code for your server Method items.

    With that being said, asynchronous programming is built into JavaScript, so it would be possible to write all of your business logic inside of a synchronous server method and then call that method asynchronously from a client-side JavaScript method so that your user does not have to wait for the server method to execute. The gist that Angela linked to contains an example of how to do this. I believe that sample was written against 12.0 where we moved more of the client-side logic to use asynchronous code.


    Christopher Gillis

    Aras Labs Software Engineer