开发者

How do I know if I'm doing Async Page correctly

开发者 https://www.devze.com 2023-03-26 19:10 出处:网络
I have a aspx with this directive: <%@ Page Language=\"C#\" AutoEventWireup=\"true\" CodeFile=\"Logs.aspx.cs\" Inherits=\"Logs_Logs\" Async=\"true\" %>

I have a aspx with this directive:

<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Logs.aspx.cs" Inherits="Logs_Logs" Async="true" %>

And the .cs:

.....

private readonly Action<string> zipArquivoAction;

public Logs_Logs()
{
    zipArquivoAction = ZipArquivo;
}

protected void LkbGZip_Click(object sender, EventArgs e)
{
    LinkButton lkbGZip = (LinkButton) sender;
    AddOnPreRenderCompleteAsyn开发者_高级运维c(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);
}

If I put a breakpoint in any method and call System.Threading.Thread.CurrentThread, always return the same Thread, what means that I am not using IO Thread, right?

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


Turn on tracing and look for calls to Begin AsyncOperation and End AsyncOperation. These should appear after End PreRender.

How do I know if I'm doing Async Page correctly

For more see:

Asynchronous Pages in ASP.NET 2.0

0

精彩评论

暂无评论...
验证码 换一张
取 消