[英]Long running request broke automatically in AppHarbor
我有一个在appharbor上运行的代码,在其中将一些数据流传输到客户端。 理想情况下,它的请求响应时间可能很长,可能是30-40分钟。
流式传输的内容是非缓冲的,这意味着响应不会保留很长时间,但会尽快写入并持续到指定时间。 我已经提到了以下代码,但是响应10分钟后应用程序失败。 有人可以让我知道这是怎么回事。
public class TestWaitResult : ActionResult
{
int _timeToWait;
object o = new object();
TextWriter output;
HttpResponseBase r;
int _sleepTimer;
public TestWaitResult(int timeToWait, int sleepTimer)
{
_timeToWait = timeToWait;
_sleepTimer = sleepTimer;
}
public override void ExecuteResult(ControllerContext context)
{
context.HttpContext.Response.Buffer = context.HttpContext.Response.BufferOutput = false;
r = context.HttpContext.Response;
output = context.HttpContext.Response.Output;
while (r.IsClientConnected)
{
Log("Executing...");
System.Threading.Thread.Sleep(_sleepTimer * 1000);
if ((_timeToWait = _timeToWait - _sleepTimer) <= 0)
{
Log("Timetowait exceeds");
break;
}
}
}
private void Log(string message)
{
lock (o)
{
try
{
if (r.IsClientConnected)
{
output.WriteLine("<br/>{0} : {1}", DateTime.Now.ToString("hh:mm:ss.fff"), message);
}
}
catch (Exception ex)
{
throw;
}
}
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.