Jump to content
  • Advertisement
Sign in to follow this  

[web] Asp Net - Asynchronous Web requests

This topic is 2655 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I've created a site using DotNetNuke so that I can use C# .Net. This is a general ASP. Net question rather than one specific to DNN. However, If you're fluent with DNN that would be helpful.

So, I've got a page which contains a UserControl. When this page is opened, I am making use of the OnInit() method which is part of UserControl. In this method, I am retrieving data, via an external API, which makes asynchronous web-requests. As a side not, it seems I needed to launch this async call on a new thread, since for some unknown reason, I couldn't use an asynchronous call (which is synchronous under the hood).

I am blocking the flow of the OnInit(), so that I can get the data before the page loads and create UserControls dynamically, based on the returned data. To block the page load, I am using a ManualResetEvent, on which I call Set(), on the new thread I mentioned, once the data has been retrieved.

I'm fairly new to ASP Net web development, and I'm not sure if what I'm doing is the most efficient way.

Would it be better to gather data before even opening the display page? For example, if I had an intermediate page that handles the async download, and then the main page which displays the data, would that be a better method? How could i pass the data on? Is it possible?


Share this post

Link to post
Share on other sites
Let me get this straight. You are rendering a page that has a UserControl that needs data that can be found at a different site. How is the data obtained? Is it through a web service? Is it a normal HTTP request? That's the part I'm having a problem understanding.

Also, what are you trying to accomplish? Does the user submit a request that takes a while to process?

Assuming that you have to do this asynchronously:
Normally in these types of scenarios, what I do is submit the request via the client using an AJAX call to a web service, which starts the process and returns some unique key. This web service behind the scenes can submit the request to some location that another thread or process can pick up and start processing.

Back on the client side, you poll another web service method to check the status of the request every, say, 5 seconds. That method returns true/false to indicate if the data is ready. When it is, your page can then do a postback and on the postback, your page with the UserControl can then pick up the data and do what it needs.

Share this post

Link to post
Share on other sites
Sign in to follow this  

  • Advertisement

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!