[英]How do I know if I'm doing Async Page correctly
我有这个指令的aspx:
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Logs.aspx.cs" Inherits="Logs_Logs" Async="true" %>
和.cs:
.....
private readonly Action<string> zipArquivoAction;
public Logs_Logs()
{
zipArquivoAction = ZipArquivo;
}
protected void LkbGZip_Click(object sender, EventArgs e)
{
LinkButton lkbGZip = (LinkButton) sender;
AddOnPreRenderCompleteAsync(BeginAsyncOperation, EndAsyncOperation, lkbGZip.CommandArgument);
}
IAsyncResult BeginAsyncOperation(object sender, EventArgs e, AsyncCallback cb, object state)
{
return zipArquivoAction.BeginInvoke((string)state, cb, state);
}
void EndAsyncOperation(IAsyncResult ar)
{
zipArquivoAction.EndInvoke(ar);
}
private void ZipArquivo(string arquivoCaminho)
{
System.Threading.Thread.Sleep(10000);
}
如果我在任何方法中都设置断点并调用System.Threading.Thread.CurrentThread,则始终返回相同的Thread,这意味着我没有使用IO Thread,对吗?
System.Threading.Thread.CurrentThread
{System.Threading.Thread}
base {System.Runtime.ConstrainedExecution.CriticalFinalizerObject}:
{System.Threading.Thread}
ApartmentState: MTA
CurrentCulture: {pt-BR}
CurrentUICulture: {pt-BR}
ExecutionContext: {System.Threading.ExecutionContext}
IsAlive: true
IsBackground: true
IsThreadPoolThread: true
ManagedThreadId: 5
Name: null
Priority: Normal
ThreadState: Background
打开跟踪并查找对Begin AsyncOperation和End AsyncOperation的调用。 这些应该出现在End PreRender之后。
有关更多信息,请参见:
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.