This project is read-only.


Topics: General
Sep 4, 2011 at 12:17 AM



Are there any plans to support async/await within Orchard. The MVC4 roadmap indicates there are plans to introduce the following


Task and Task<T> Support for AsyncController Classes

Writing asynchronous action methods has been tricky with existing versions of ASP.NET MVC. For example, the following ASP.NET MVC 3 code snippet shows an example of an action method that calls into two different asynchronous services.

public void IndexAsync(string city) {

    NewsService newsService = new NewsService();
    newsService.GetHeadlinesCompleted += (sender, e) =>
        AsyncManager.Parameters["headlines"] = e.Value;

    SportsService sportsService = new SportsService();
    sportsService.GetScoresCompleted += (sender, e) =>
        AsyncManager.Parameters["scores"] = e.Value;

public ActionResult IndexCompleted(string[] headlines, string[] scores, string[] forecast) {
    return View("Common", new PortalViewModel  {
        NewsHeadlines = headlines,
        SportsScores = scores,

Using ASP.NET MVC 4 and the Visual Studio Async CTP (or in the future, C# 5, which will support the await keyword), that asynchronous action method becomes:

public async Task<ActionResult> Index(string city) {
    var newsService = new NewsService();
    var sportsService = new SportsService();
    return View("Common",
        new PortalViewModel {
        NewsHeadlines = await newsService.GetHeadlinesAsync(),
        SportsScores = await sportsService.GetScoresAsync()
Sep 4, 2011 at 6:01 AM

That relies on features of a version of .NET that is not out yet. When it's out, we can start using it.

Sep 4, 2011 at 2:39 PM

HI Bertrand,


How about adding AsyncController support within Orchard?. We have use cases for our information portal, where we would have to make multiple webservice calls for a single page. These can be done asynchronously instead of making synchronous calls. 

Even enabling the first step in my above post would be a good way forward.

Sep 5, 2011 at 6:07 AM

Sure, that's a different question, and would be an excellent contribution.

Sep 5, 2011 at 6:21 AM

Adding Async support for a sophisticated framework could be best done by the core authors of the framework. Any chance of prioritizing this within the Orchard team?

I would be happy to write the first examples of how to use the async framework.. :)



Sep 5, 2011 at 6:22 AM

Sure, we can consider it, but it will depend on what else is on the map.

Sep 5, 2011 at 3:28 PM

That would be great. This could make a tremendous improvement overall for performance of pages we are looking to build. I will look at whether the same thing could be done using sync controller and F#.


Pattern #2:  Parallel I/O Asyncs


So far we have only seen parallel CPU-bound programming with F#. One key thing about F# async programming is that you can use it for both CPU and I/O computations. This leads to our second pattern: Parallel I/O Asyncs, i.e. doing I/O operations in parallel (also known as overlapped I/O). For example, the following requests multiple web pages in parallel and reacts to the responses for each request, and returns the collected results.


open System

open System.Net


open Microsoft.FSharp.Control.WebExtensions


let http url =

    async { let req =  WebRequest.Create(Uri url)

            use! resp = req.AsyncGetResponse()

            use stream = resp.GetResponseStream()

            use reader = new StreamReader(stream)

            let contents = reader.ReadToEnd()

            return contents }


let sites = ["";





let htmlOfSites =

    Async.Parallel [for site in sites -> http site ]

    |> Async.RunSynchronously


The above code sample shows the essence of the Parallel I/O Asyncs pattern:

(a)     “async { … }” is used to write tasks which include some asynchronous I/O.

(b)   These are composed in parallel using the fork-join combinator Async.Parallel


In this case, the composition is executed using Async.RunSynchronously, which synchronously waits for the overall result


Sep 9, 2011 at 4:14 AM

Hi Bertrand,

Any possibility of having this support in the upcoming 1.3 release?. This could make a tremendous difference for performance of pages and our website.



Sep 9, 2011 at 4:48 AM

If there is a contribution, we might consider it. Otherwise, we simply don't have enough time.

Sep 9, 2011 at 4:54 AM

Understand Bertrand. Would someone from the core team give some pointers on areas to work on. I remember someone mentioning the Autofac version needs to be updated. 



Sep 9, 2011 at 5:06 AM

The new steering committee will give that sort of direction once it's formed. In the meantime, yes, upgrading dependencies is a good one to look at.