WCF 服务应用程序计时器

发布于 2024-10-10 19:05:49 字数 765 浏览 5 评论 0原文

我有一个带有 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

沉鱼一梦 2024-10-17 19:05:49

它将继续运行,直到主机应用程序启动并运行。如果您的服务托管在 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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文