Windows服务,计时器和穿线 [英] Windows Services, Timers & Threading

查看:66
本文介绍了Windows服务,计时器和穿线的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个自托管的WCF服务。我有2个方法需要定期运行,因此主机服务有2个System.Threading.Timers。 

I have a self hosted WCF service. I have 2 methods that need to run periodically so the Host Service has 2 System.Threading.Timers. 


  1. Timer1的运行时间很长。 可能需要一分钟才能运行。
  2. Timer2的方法很快但必须每10秒运行一次。

我的第一个想法是,每个计时器都会在一个单独的线程上运行,我应该能够开箱即用。 我错了。 我无法使Timer2保持一致,因为两个定时器
和/或服务器负载之间似乎存在依赖关系。  Timer2没有给我一个干净的执行模式。

My first thought was that each timer would run on a separate thread and I should be able to get this right out of the box.  I was incorrect.  I can't get Timer2 to be consistent because there seems to be a dependency between the two timers and/or the server load.  Timer2 doesn't give me a clean execution pattern.

在尝试解决这个问题时,我在Timer1的方法调用周围放了一个System.Threading.Tasks.Task。 我希望这会释放资源,以便Timer2可以干净利落地运行。  仍然,没有运气。

In trying to fix this, I put a System.Threading.Tasks.Task around the method call on Timer1.  I expected this to release resources so that Timer2 can run cleanly.  Still, no luck.

这让我很难过。 知道为什么Timer2不会以一致的模式触发吗?

This has me stumped.  Any idea why Timer2 doesn't fire on a consistent pattern?

感谢您的帮助,Joel。

Thanks for your help, Joel.

申请表开发商制造

推荐答案

您好,

'架构一般'论坛是讨论与微软平台上的架构和设计解决方案相关的一般问题和经验。

The 'Architecture General' forum is to Discuss general issues and experiences related to architecture and designing solutions on the Microsoft platform.

我会在
Visual Studio Languages
论坛。

Karl


这篇关于Windows服务,计时器和穿线的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆