我有一个很长的流媒体操作,如果客户端断开连接,我希望能够取消。
如何知道连接状态或客户端是否已断开连接? 客户端很可能是一个Web浏览器。
public async Task<HttpResponseMessage> SendStream(string account, string container)
{
var responseContent = new PushStreamContent(async (stream, content, context) =>
{
do
{
//get some data
stream.Write(chunkData, 0, chunkLength);
} while (IsClientStileConnected && moreWork);
}, "application/octet-stream");
var response = Request.CreateResponse(HttpStatusCode.OK);
response.Content = responseContent;
return response;
}