Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6902655
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T07:49:31+00:00 2026-05-27T07:49:31+00:00

I am not so good at asynchronous programming so the question might be at

  • 0

I am not so good at asynchronous programming so the question might be at the low level.

I have created an async method as below with Async CTP on ASP.NET MVC 4 Dev. Preview:

public class Movie
{
    public string Title { get; set; }
    public string Url { get; set; }
    public string BoxArtUrl { get; set; }
}

public class MovieM {

    public IEnumerable<Movie> M2009 { get; set; }
    public IEnumerable<Movie> M2010 { get; set; }
    public IEnumerable<Movie> M2011 { get; set; }
}

public class HomeController : AsyncController  {

    public async Task<ActionResult> GetMoviesM()  {

        var profiler = MiniProfiler.Current; // it's ok if this is null

        var pageSize = 1000;
        var imageCount = 0;

        using (profiler.Step("Start pulling data (Async) and return it")) { 

            var m2009 = await QueryMoviesAsync(2009, imageCount, pageSize);
            var m2010 = await QueryMoviesAsync(2010, imageCount, pageSize);
            var m2011 = await QueryMoviesAsync(2011, imageCount, pageSize);

            return View(new MovieM { 
                M2009 = m2009,
                M2010 = m2010,
                M2011 = m2011
            });
        }
    }

    XNamespace xa = "http://www.w3.org/2005/Atom";
    XNamespace xd = "http://schemas.microsoft.com/ado/2007/08/dataservices";
    XNamespace xm = "http://schemas.microsoft.com/ado/2007/08/dataservices/metadata";

    string query = "http://odata.netflix.com/Catalog/Titles?$filter=ReleaseYear eq {0}&$skip={1}&$top={2}&$select=Url,BoxArt";

    async Task<IEnumerable<Movie>> QueryMoviesAsync(int year, int first, int count)  {

        var client = new WebClient();
        var url = String.Format(query, year, first, count);
        var data = await client.DownloadStringTaskAsync(new Uri(url));
        var movies =
            from entry in XDocument.Parse(data).Descendants(xa + "entry")
            let properties = entry.Element(xm + "properties")
            select new Movie
            {
                Title = (string)entry.Element(xa + "title"),
                Url = (string)properties.Element(xd + "Url"),
                BoxArtUrl = (string)properties.Element(xd + "BoxArt").Element(xd + "LargeUrl")
            };
        return movies.AsEnumerable();
    }
}

The code works just fine. When we run the same function on a desktop app (a WPF App for instance), we can see a tangible performance difference. The UI isn’t blocked, the data is being pushed to screen instantly when it is available.

But on a web application, I really cannot see a difference. I also created the same function as sync and the both of them are nearly the same.

What I would like to know is that:

  1. I run this app on a machine which has Intel Core 2 Duo CPU T5750 2.00GHz. Do number of processors effect the performance of asynchronous thread on C#?
  2. Am I doing something wrong here from a web application point of view?
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-27T07:49:32+00:00Added an answer on May 27, 2026 at 7:49 am

    When we run the same function on a desktop app (a WPF App for instance), we can see a tangible performance difference. The UI isn’t blocked, the data is being pushed to screen instantly when it is available.

    This is a common misconception. The method you posted is slightly slower than its synchronous equivalent, but in a UI app it is more responsive, and therefore appears more performant.

    In an ASP.NET scenario, the page is only rendered when all asynchronous requests have completed; that is why you don’t see a difference.

    You can make it actually more performant by parallelizing your requests:

    var m2009Task = QueryMoviesAsync(2009, imageCount, pageSize);
    var m2010Task = QueryMoviesAsync(2010, imageCount, pageSize);
    var m2011Task = QueryMoviesAsync(2011, imageCount, pageSize);
    await Task.WhenAll(m2009Task, m2010Task, m2011Task);
    var m2009 = await m2009Task;
    var m2010 = await m2010Task;
    var m2011 = await m2011Task;
    

    This will improve the performance for both desktop and ASP.NET.

    Your original code uses serial composition (one await at a time). In this case, the code is running asynchronously, but the request is not completed any faster. There is still a benefit to using async/await like this: the request does not tie up an ASP.NET thread, so your service can scale up more. In the UI world, the UI thread does not get tied up, so it’s more responsive. But for both ASP.NET and UI, the total time to complete the GetMoviesM method is not reduced by making it async.

    Parallel composition (using Task.WhenAll or Task.WhenAny) allows GetMoviesM as a whole to run faster, since it does the requests in parallel. In addition, you get the thread benefits mentioned above.

    In this case, the number of processors does not matter. They only come into play when you’re doing processing on the thread pool (e.g., Task.Run), not when doing I/O. (This is a simplification, but true enough).

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am not good at SQL Server 2000. I have a comma-delimited list of
Original Question: i read that for RESTful websites. it is not good to use
I am trying to make a client with asynchronous. I am not good in
I have a WCF service client implemented using the asynchronous event (using /async and
Good evening fellow stackers, I have a mutex and threaded related question about //
Good day, I have a ASP.net MVC app that needs to upload files to
I'm learning C# asynchronous socket programming, and I've learned that it's a good idea
I'm not good with JavaScript, and this is Google's code. I'm getting a object
It seems not good for me, reporting errors like 'General Error: '+...., Is there
I am not good at jsp but I wondered what can cause such a

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.