我在 ASP.NET 中有以下 SSE 处理程序
Response.ContentType = "text/event-stream";
while (true)
{
Response.Write(string.Format("data: {0}\n\n", DateTime.Now.ToString()));
Response.Flush();
System.Threading.Thread.Sleep(1000);
}
即使我关闭了客户端应用程序,它也会无限期地运行。如何通知服务器停止处理程序?
我在客户端上试过:
var source = new EventSource('Handler.aspx');
window.onunload = function() {
source.close();
}
但我没有成功。