c# - 在 IIS 上托管 ASP.NET 解决方案后启动系统计时器
问题描述
我创建了一个 MVC ASP.NET Standard(不是 .NET Core)解决方案并添加了一个 System.Timers.Timer
。Global.asax.cs
我在注册服务之前启动了计时器。
托管后,即使我在Application_Start
函数将启动的位置启用计时器并按如下方式挂钩计时器,计时器也不会启动,直到客户端调用网站:
// Create a timer with a two second interval.
aTimer = new System.Timers.Timer(intervalInMiliseconds);
// Hook up the Elapsed event for the timer.
aTimer.Elapsed += OnTimedEvent;
aTimer.AutoReset = true;
aTimer.Enabled = true;
我的问题是,如果我想让计时器启动,无论是否有连接的用户,我应该在哪里启动计时器?我可以使用 ASP.NET Standard 还是应该使用 .NET Core?
我的场景是,我将创建一个托管 SignalR 集线器的 Windows 服务,并将定期向所有连接的用户发送消息。我想对 IIS 做同样的事情。
解决方案
推荐阅读
- python - “函数参数”的引用计数与“Python 的函数堆栈”的引用计数有何不同 - Python
- python-3.x - 我无法在 python 中使用 OAUTH 2.0 SAML Assertion Bearer 流获取访问令牌
- python - Postgres 现有列不存在错误
- powershell - PowerShell 事件查看器错误
- python - 如何更新脑切片的 Tkinter 图中的值,以便能够从 4D 图像中翻阅不同的脑容量
- angular - Rxjs zip 与 rest 调用两次调用
- excel - VBA根据表的数据列表锁定/解锁每一行
- javascript - 在 React 中切换语言而不使用外部库
- jsf - 为什么 UTF8 字符编码在 JSF 中不起作用?
- core - MS chart 将图表缩放到一个区域