I have read about ASP.NET Asynchronous Page, after reading some material I'm still a bit not clear about the concept. Therefore, I write something like this below to seek for verification that is this an Asynchronous Page? Or I have misunderstood the concept? Thanks you very much for your insights.
我已经阅读了有关ASP.NET异步页面的内容,在阅读了一些材料后,我仍然对这个概念不太清楚。因此,我写下面这样的内容来寻求验证,这是一个异步页面?或者我误解了这个概念?非常感谢您的见解。
<%@ Page Language="C#" AutoEventWireup="true" Async="true" CodeBehind="Default.aspx.cs" Inherits="WebApplication1._Default" %>
Code behind:
代码背后:
public partial class _Default : System.Web.UI.Page
{
System.ComponentModel.BackgroundWorker bw = new System.ComponentModel.BackgroundWorker();
protected void Page_Load(object sender, EventArgs e)
{
bw.DoWork += bw_DoWork;
bw.RunWorkerCompleted += bw_RunWorkerCompleted;
bw.RunWorkerAsync();
}
void bw_DoWork(object sender, System.ComponentModel.DoWorkEventArgs e)
{
System.Threading.Thread.Sleep(5000);
}
void bw_RunWorkerCompleted(object sender, System.ComponentModel.RunWorkerCompletedEventArgs e)
{
Form.Controls.Add(new LiteralControl("<p>Finished.</p>"));
}
}
1 个解决方案
#1
2
I'd say no, that is not the way an asynchronous page is typically implemented in ASP.NET.
我会说不,这不是异步页面通常在ASP.NET中实现的方式。
First, the worker process (the ASP.NET engine) uses a pool of threads to serve the requests that arrive to the server. So, you don't have to use System.ComponentModel.BackgroundWorker
at all in your code.
首先,工作进程(ASP.NET引擎)使用一个线程池来提供到达服务器的请求。因此,您不必在代码中使用System.ComponentModel.BackgroundWorker。
I'm not an expert on the matter, so I think it's best for you to grasp the fundamentals straight from the source. Here are 2 good blog posts in regards to asynchronous pages in ASP.NET:
我不是这方面的专家,所以我认为最好直接从源头上掌握基础知识。以下是关于ASP.NET中异步页面的2篇好文章:
- Wicked Code - Asynchronous Pages in ASP.NET 2.0
- Wicked Code - ASP.NET 2.0中的异步页面
- Using Asynchronous Methods in ASP.NET 4.5
- 在ASP.NET 4.5中使用异步方法
#1
2
I'd say no, that is not the way an asynchronous page is typically implemented in ASP.NET.
我会说不,这不是异步页面通常在ASP.NET中实现的方式。
First, the worker process (the ASP.NET engine) uses a pool of threads to serve the requests that arrive to the server. So, you don't have to use System.ComponentModel.BackgroundWorker
at all in your code.
首先,工作进程(ASP.NET引擎)使用一个线程池来提供到达服务器的请求。因此,您不必在代码中使用System.ComponentModel.BackgroundWorker。
I'm not an expert on the matter, so I think it's best for you to grasp the fundamentals straight from the source. Here are 2 good blog posts in regards to asynchronous pages in ASP.NET:
我不是这方面的专家,所以我认为最好直接从源头上掌握基础知识。以下是关于ASP.NET中异步页面的2篇好文章:
- Wicked Code - Asynchronous Pages in ASP.NET 2.0
- Wicked Code - ASP.NET 2.0中的异步页面
- Using Asynchronous Methods in ASP.NET 4.5
- 在ASP.NET 4.5中使用异步方法