WCF 服务应用程序计时器
我有一个带有 REST 服务的 WCF 服务应用程序项目,其 InstanceContextMode 设置为 Single。它包含一个计时器,我想用它来定期检查和检查注册情况。
直到有人第一次调用该服务后,计时器才会启动。我想知道的是,是否存在像 ASP.NET 网站那样的某种超时,之后如果一段时间内没有人使用它,IIS 会停止服务,或者计时器会继续运行。
[ServiceContract]
public interface IRegistrationService
{
[OperationContract, WebGet...]
void Register(...);
}
[ServiceBehavior(InstanceContextMode = InstanceContextMode.Single)]
public class RegistrationService : IRegistrationService
{
private Timer timer;
public RegistrationService()
{
this.timer = new System.Timers.Timer(1000 * 60 * 5);
this.timer.Elapsed += OnTimerElapsed;
this.timer.Start();
}
private void OnTimerElapsed(object sender, ElapsedEventArgs e)
{
//
}
}
I have a WCF Service Application project with a REST service which has it's InstanceContextMode set to Single. It contains a timer which I want to use to regularly go through and check the registrations.
The timer does not start until someone calls the service for the first time. What I want to know is, is there some kind of timeout like in ASP.NET websites after which IIS will stop the service if nobody used it for a while or will the timer continue running.
[ServiceContract]
public interface IRegistrationService
{
[OperationContract, WebGet...]
void Register(...);
}
[ServiceBehavior(InstanceContextMode = InstanceContextMode.Single)]
public class RegistrationService : IRegistrationService
{
private Timer timer;
public RegistrationService()
{
this.timer = new System.Timers.Timer(1000 * 60 * 5);
this.timer.Elapsed += OnTimerElapsed;
this.timer.Start();
}
private void OnTimerElapsed(object sender, ElapsedEventArgs e)
{
//
}
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
它将继续运行,直到主机应用程序启动并运行。如果您的服务托管在 IIS 中并且禁用了 Keep-Alive,它将被关闭,但如果是 winforms 或 Windows 服务主机,对象将持续存在,直到应用程序关闭。要关闭此对象,请将服务设置为 Disposable,并在计时器过期时处置该类。
It will continue running untill host app is up and running. If your service is hosted in IIS and Keep-Alive is disabled, it will be closed, but in case of winforms or windows service host, object will persist untill the application is closed. To close this object make the service Disposable and dispose the class when timerElapsed.