Page.AsyncTimeout - 无尽的超时? [英] Page.AsyncTimeout - endless timeout?

查看:157
本文介绍了Page.AsyncTimeout - 无尽的超时?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我看到为例永远的iframe 实施(彗星模拟),所以我决定来测试它,但是添加的异步的办法,这样就没有阻止。

I saw an example of forever iframe implementation ( comet simulation ) , so I decided to test it but with the addition of asynchronous approach , so that there will be no blocking.

pretty简单:

我有一个网页( index.html的)以隐藏 IFRAME 其中有SRC EM> AdminPush.aspx

I have a page (index.html) with hidden iframe which has SRC of AdminPush.aspx:

/*1*/           protected void Page_Load(object sender, EventArgs e)
/*2*/           {
/*3*/               UpdateMessage();
/*4*/           }
/*5*/   
/*6*/   
/*7*/           protected void UpdateMessage()
/*8*/           {
/*9*/               HttpContext.Current.Response.ContentType = "text/html";
/*10*/               Response.Write("<script  >parent.UpdateMessage(DateTime.Now.Second)</script>");
/*11*/               Response.Flush();
/*12*/   
/*13*/               //async part goes here  !!
/*14*/               this.RegisterAsyncTask(new PageAsyncTask(async cancellationToken =>
/*15*/                                       {
/*16*/                                            await Task.Delay(2000, cancellationToken);
/*17*/                                            UpdateMessage();
/*18*/                                       }));
/*19*/           }

AdminPush.aspx 页我增加:

异步=真正的

在HTML页面( index.html的)我说:

On the html page (index.html) I added :

function UpdateMessage(Message)
        {
          console.log(Message);
        }


    function setupAjax() //body Onload - calls it.
    {
        var iframe = document.createElement("iframe");
        iframe.src = "adminpush.aspx"; 
        iframe.style.display = "none";
        document.body.appendChild(iframe);
    }

所以基本上IFRAME正与脚本命令对应的注入,这将更新它的iframe index.html的的母公司。

这是工作。

但是,当我测试了它 - 它45秒后停止更新

But when I tested it - it stopped updating after 45 seconds.

我认为它与在web.config中的requestTimeout道具做 - 但它不是

I thought it had to do with requestTimeout prop in web.config - but it wasnt.

这是有关在 AdminPush.aspx 页缺少 AsyncTimeOut 道具。

It was related to the missing AsyncTimeOut prop in the AdminPush.aspx page.

问题1:

据的 MSDN AsyncTimeout:

According to msdn AsyncTimeout :

获取或设置超时时间间隔值时使用
  处理异步的任务

Gets or sets a value indicating the time-out interval used when processing asynchronous tasks.

但它也说:

这是包含在允许的时间间隔为完成一个TimeSpan
  异步的任务。默认的时间间隔为45秒。

A TimeSpan that contains the allowed time interval for completion of the asynchronous task. The default time interval is 45 seconds.

请注意,我延迟2秒,每次

在第一I的超时设置为1分钟,但随后也失败了。我认为超时应该是关于每个的操作,而不是总和(所有异步操作)

at first I set the timeout to 1 minute , but then it failed also. I thought that the timeout should be regarding each operation , and not to sum(all async operations)

为什么会这样呢?它假设是超时异步任务! (单),但它的行为与总和(任务)

Why is it like that ? it suppose to be timeout for async task ! (single) but it behaves as sum(tasks)

这里的措辞具有误导性。任何澄清?

The wording here are misleading. any clarification ?

问题2:

我需要将其设置为最大的值。的什么的是价值?但尽管如此,我需要它,支持的浏览器很长一段时间。所以恐怕这个值将没有帮助。

I need to set it to max value. what is that value ? but still , I need it so support a browser for a very long time. so I'm afraid that this value won't help either.

有什么办法,我可以重置此值(N次循环之后)?

Is there any way I can RESET this value (after n cycles) ?

我知道有其他的解决方案/库,例如signalR它正在做的工作,不过,这并不prevent学习其他的东西怎么完成。

推荐答案

异步页面的想法是释放IIS让更多的用户可以送达,如果你创建一个网页,从来没有完成时,你会吃了你的全部资源。

The idea of Asynchronous Pages is to free IIS so more users can be served, if you create a page that "never" finishes, you will eat up all your resources.

这是说......如果你仍然想这样做...

That been said... if you still want to do it...

我们知道(文档),异步工作的页面通过拆分页面的执行,2 ...一切的后台任务和之后的所有任务之前,以这种方式IIS可以处理更多的请求,同时在后台任务完成他们的工作。 (还有更多的它,但现在就足够了)

We "know" (documentation), Asynchronous Pages work by splitting the execution of the page in 2... everything BEFORE the Background Tasks and everything AFTER the tasks, in that way IIS can process more requests while the background tasks finish their work. (there is more to it, but that is enough for now)

所以......他们 必须要创建某种任务管理器(像根/主要任务)的所有执行按顺序登记工作,以这种方式开始IIS处理页面,会调用任务管理器,释放IIS,任务管理器会处理的任务,当它完成,它返回控制到IIS。

So... they "must" be creating some kind of Task Manager (like a root/main task) that executes all the registered tasks in sequence, in that way IIS starts processing the page, fires up the task manager, frees IIS, the task manager keeps processing the tasks and when it finishes, it returns control to IIS.

这可以解释为什么AsyncTimeout控制所有注册的任务,而不是一个接一个(超时实际应用到任务管理器)。

That would explain why the AsyncTimeout controls all the registered tasks instead of one-by-one (The timeout is actually applied to the Task Manager).

我测试了code的变化与6000秒的超时和它的作品:

I tested a variation of your code with a timeout of 6000 seconds and it works:

C#:

protected void Page_Load(object sender, EventArgs e)
{
    Page.RegisterAsyncTask(new PageAsyncTask(ProcessTask));
}

protected async Task ProcessTask()
{
    await Task.Delay(1000);
    Response.Write(DateTime.Now.ToLongTimeString() + "<br/>");
    Response.Flush();
    Page.RegisterAsyncTask(new PageAsyncTask(ProcessTask));
}

ASPX:

<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Default.aspx.cs" Inherits="Sample03.Default" Async="true" AsyncTimeout="6000" %>

希望它帮助。

这篇关于Page.AsyncTimeout - 无尽的超时?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆