来自流的XMLReader问题 [英] XMLReader from a stream Problem
问题描述
我有一台服务器在发生警报时发出XML消息。
我使用Webrequest连接到服务器并读取流。
我的问题是服务器只在发出警报时发出消息。
目前我有一个XMLReader.read函数正在侦听下一个警报但如果程序关闭则可能有一段时间在XMLReader.read函数返回之前,可以终止进程。
我一直试图找到一种方法来检测在尝试读取之前是否有要处理的流中的数据,或者强制退出读取XMLReader.read函数的其他方法。 br />
任何建议赞赏
谢谢
Hi, I have a server that sends out an XML message when an alarm occurs.
I have used Webrequest to connect to the server and to read the stream.
My problem is that the server only sends out messages when there is an alarm.
Currently I have a XMLReader.read function listening for the next alarm but if the program is shut down there can be some time before the XMLReader.read function returns and the process can be terminated.
I have been trying to find a way to detect if there is data in the stream to be processed before the read is attempted or some other way to force an exit from the read XMLReader.read function.
Any advice appreciated
Thank You
推荐答案
这应该可以帮到你确定连接的状态。
This should help you to determine the status of the connection.
//geting the response from the request url
var response = (HttpWebResponse)httpRequest.GetResponse();
if (response == null || response.StatusCode != HttpStatusCode.OK)
{
//damn, something happens with the connection
}
这篇关于来自流的XMLReader问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!