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?