有没有办法确定 IIS 或网站已被停止?
我有一个 WCF 服务,托管在带有 IIS 7.5 和 Windows 2008 的 AppFabric 上。该服务设置为按照建议自动启动。 当服务启动时,它会进入一个永远不会结束的 while 循环,请记住这是所需的行为。 while 循环应该处理一些我不知道什么时候可用的数据。
问题是当我关闭网站或 IIS 时,服务仍在运行。所以我的问题是:
有没有办法确定 IIS 或网站已停止?
有没有更好的方法来实现这种永无休止的行为?
希望这里有足够的信息。
I have a WCF Service that I am hosting on AppFabric with IIS 7.5 and Windows 2008. The service is set to auto start as recommended.
When the service starts it goes into a while loop that never ends, keep in mind that this is the desired behavior.
The while loop is supposed to process some data that I don't know when its going to be available.
The problem is when I shut down the website, or IIS, the service keeps running. So my questions are:
Is there a way to identify that IIS or the website had been stopped?
Is there a better way of achieving this never ending behavior?
Hopefully there is enough information here.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
好的,现在您正在运行无限轮询循环。这种设计可能很有意义,尽管它很不寻常。
我建议您启动一个单独的线程来进行轮询。您的线程代码应如下所示:
关闭时,所有线程都将中止。这是检测关机的技巧。
像这样启动线程:
Ok, so you have an infinite polling loop running. This design might well make sense, although it is unusual.
I recommend that you start a separate thread which does the polling. Your threads code should look like this:
When shutting down all threads will be aborted. This is the trick to detect shutdown.
Start the thread like this:
关于网站状态检测问题:如果您知道网站名称,则可以使用 Microsoft.Web.Administration API 来确定网站是否已启动。 上提供了一些很好的示例
学习 IIS 网站 ,我同意其他人在这里关心为什么你使用无限循环......
In regards with the Web Site status detection question: If you know the site name, you can use Microsoft.Web.Administration API to determine if the site has been started or not. Some good examples are available on Learn IIS website
However, I second others concern here as to why you are using an infinite loop...