简体   繁体   中英

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM