我有一个带有 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)
{
//
}
}