我想检查连接是否仍然打开。如果不是,我就停止这个过程。
//Process request code goes here
while (!isComplete) {
//Check HttpListenerRequest if connection is still open...
if (IsTimedOut && !timeoutTriggered)
{
timeoutTriggered = triggerTimeout();
}
Thread.Sleep(100);
}
stopWatch.Stop();
//Process response code goes here我怎么能这么做?
发布于 2017-06-06 15:22:38
我已经用写/刷新对解决了这个问题。当连接关闭时,刷新引发异常。
try
{
//Checks whether the connection is still open
var encoding = Encoding.Default;
byte[] utf8Bytes = Encoding.Convert(encoding, Encoding.UTF8, encoding.GetBytes(" "));
listenerContext.Response.OutputStream.Write(utf8Bytes, 0, utf8Bytes.Length);
listenerContext.Response.OutputStream.Flush();
}
catch (Exception e)
{
Console.WriteLine(e);
eventStream.TriggerEvent(new ActionEventArgs(this, ActionEventStreamer.SYSTEM_CANCEL));
break;
}https://stackoverflow.com/questions/44337122
复制相似问题