San*_*osh 2 .net c# asp.net multithreading asynchronous
如何在ASP.NET页面中实现异步加载?
我的ASP.NET页面中有3个部分.所有部分都是独立的.
LoadSection1();
LoadSection2();
LoadSection3();
Run Code Online (Sandbox Code Playgroud)
每个部分大约需要15秒.我想使用异步加载减少页面加载时间.
我试过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();
Run Code Online (Sandbox Code Playgroud)
页面在完成所有线程后加载.但是每当我从线程得到响应时,我都需要显示每个部分的数据.例如,如果Thread1完成,我想显示Section1的数据(即使thread2和3仍在运行.).我怎样才能在.NET中实现这一目标?