c# - ASP.NET页面如何实现异步加载?

标签 c# asp.net .net multithreading asynchronous

如何在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/

相关文章:

java - 确保套接字编程中的数据传递

c# - 根据键名选择枚举值

c# - ASP.NET Core 服务不会重定向 http :localhost:<https-port> to https schema

c# - ASP .NET - 设置 DetailsView TextBox 的值

c# - JIT 或 CLR 中可能存在的错误

c# - lambda c# 中 "() =>"的用途是什么

c# - HasFlag 始终返回 True

c# - 使用 Autofac 将 SignalR IHubContext 注入(inject) Controller

asp.net - 从 Github 自动部署到 IIS 上?

c# - 防止后续服务调用的协商握手