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 7048743
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T02:55:42+00:00 2026-05-28T02:55:42+00:00

The preamble We’re implementing a MVC2 site that needs to consume an external API

  • 0

The preamble

We’re implementing a MVC2 site that needs to consume an external API via https (We cannot use WCF or even old-style SOAP WebServices, I’m afraid). We’re using AsyncController wherever we need to communicate with the API, and everything is running fine so far.

Some scenarios have come up where we need to make multiple API calls in series, using results from one step to perform the next.

The general pattern (simplified for demonstration purposes) so far is as follows:

public class WhateverController : AsyncController
{
    public void DoStuffAsync(DoStuffModel data)
    {
        AsyncManager.OutstandingOperations.Increment();
        var apiUri = API.getCorrectServiceUri();
        var req = new WebClient();
        req.DownloadStringCompleted += (sender, e) =>
        {
            AsyncManager.Parameters["result"] = e.Result;
            AsyncManager.OutstandingOperations.Decrement();
        };
        req.DownloadStringAsync(apiUri);
    }

    public ActionResult DoStuffCompleted(string result)
    {
        return View(result);
    }
}

We have several Actions that need to perform API calls in parallel working just fine already; we just perform multiple requests, and ensure that we increment AsyncManager.OutstandingOperations correctly.

The scenario

To perform multiple API service requests in series, we presently are calling the next step within the event handler for the first request’s DownloadStringCompleted. eg,

req.DownloadStringCompleted += (sender, e) =>
{
    AsyncManager.Parameters["step1"] = e.Result;
    OtherActionAsync(e.Result);
    AsyncManager.OutstandingOperations.Decrement();
}

where OtherActionAsync is another action defined in this same controller following the same pattern as defined above.

The question

Can calling other async actions from within the event handler cause a possible race when accessing values within AsyncManager?

I tried looking around MSDN but all of the commentary about AsyncManager.Sync() was regarding the BeginMethod/EndMethod pattern with IAsyncCallback. In that scenario, the documentation warns about potential race conditions.

We don’t need to actually call another action within the controller, if that is off-putting to you. The code to build another WebClient and call .DownloadStringAsync() on that could just as easily be placed within the event handler of the first request. I have just shown it like that here to make it slightly easier to read.

Hopefully that makes sense! If not, please leave a comment and I’ll attempt to clarify anything you like.

Thanks!

  • 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-28T02:55:43+00:00Added an answer on May 28, 2026 at 2:55 am

    It turns out the answer is “No”.

    (for future reference incase anyone comes across this question via a search)

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

Sidebar

Related Questions

Preamble: I'm creating some tables in SQL Server that will be accessed via Linq-to-entities
What sort of code should I put in preamble, such that every math fomula
Is there any single magic preamble that will make a Perl script run under
Preamble: I investigated how to version an API and found several ways to do
Preamble I'm using git as a version control system for a paper that my
Preamble: I'm working at heavy-loaded applicaion that produces large data arrays. I wrote the
Preamble: I am using ASP.NET 3.5 and AJAXControlToolkit. I am trying to use the
Preamble: I know, disabling warnings is not a good idea. Anyway, I have a
Preamble I've searched to see if I can find this question anywhere on here
The preamble: I have designed a strongly interfaced and fully mockable data layer class

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.