WCF Service Application Timer
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)
{
//
}
}
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.
精彩评论