如何在ASP.NET页面中实现异步加载?
我的 ASP.NET 页面中有 3 个部分。所有的部分都是独立的。
LoadSection1();
LoadSection2();
LoadSection3();
每个部分大约需要 15 秒。我想使用异步加载来减少页面加载时间。
我试过线程
// 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();
页面在完成所有线程后正在加载。但是每当我从线程获得响应时,我都需要显示每个部分的数据。 例如如果 Thread1 完成,我想显示 Section1 的数据(即使线程 2 和 3 仍在运行。)。我如何在 .NET 中实现这一点?
最佳答案
我会考虑使用 AJAX以便用户立即看到一些东西。
关于c# - ASP.NET页面如何实现异步加载?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8805001/