2

How to implement asynchronous loading in ASP.NET page?

I have 3 sections in my ASP.NET page. All the sections are independent.

LoadSection1();
LoadSection2();
LoadSection3();

Each section is taking around 15 seconds. I want to reduce the page load time using asynchronous loading.

I have tried with Threads

// Create thread jobs for each section
ThreadStart PipelinePerformanceThreadJob = new ThreadStart(LoadPipelineSection);
ThreadStart CampaignPerformanceThreadJob = new ThreadStart(LoadCampaignSection);
ThreadStart OperationalThreadJob = new ThreadStart(LoadOperationalSection);

// Create threads
Thread PPThread = new Thread(PipelinePerformanceThreadJob);
Thread CSThread = new Thread(CampaignPerformanceThreadJob);
Thread OSThread = new Thread(OperationalThreadJob);

// Start all the threads
PPThread.Start();
CSThread.Start();
OSThread.Start();

// Join threads with main thread
PPThread.Join();
CSThread.Join();
OSThread.Join();

Page is loading once it completed all the threads. But i need to display data for each section whenever i get response from the thread. For e.g. If Thread1 is completed, i want to display data for Section1 (even if thread2 and 3 are still running.). How can i achieve this in .NET?

1
  • 1
    which version of .net you are using Commented Jan 10, 2012 at 14:40

2 Answers 2

5

I would consider using AJAX so that the user sees something right away.

Sign up to request clarification or add additional context in comments.

2 Comments

How can i send 3 ajax requests at a time? If i use Ajax, i need to send individual request for each section. That doesn't help me in improving the performance. Please let me know if i am wrong or any other approaches using Ajax. :)
AJAX will improve your performance even if you're sending three requests since each request is asynchronous (hence, the name: Asynchronous JavaScript and XML). While your page is loading, each individual section can load independently and then render once the callback is made from the server side. So AJAX will most certainly improve your performance. Just kick off your three requests when the page loads.
1

I think that you have a couple of relatively easy options that you can try, depending on the complexity and intricacy of your page (i.e. is it static data, does everything have to post back etc):

1) Separate your page into three different pages, then add frames or iframes to your original page and direct the frames to your new pages.

2) Separate your page into three user controls and add them to the page within update panels.

In the control's codebehind, do not perform the load action on the initial page load (i.e. not postback).

To load the control content, add javascript to the window.onload event or (page.registerstartupscript) that does something simple like clicks a button in the updatepanel, to force a postback. However, ensure that you do this in a window.settimeout for each user control so that you don't have to wait for the first one to complete.

This will kick off the async loading of the user controls.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.