Skip to main content
 首页 » 编程设计

c#之Web 应用程序启动时启动计时器

2024年01月13日26mq0036

我想在我的应用程序启动时启动一个 System.Threading.Timer(也许部署是正确的词)。我看到您可以使用 Application_Start() 但这只是 fired once the first request comes to the application .我需要在应用程序运行时立即启动计时器,以便即使用户没有与网站交互,它也可以检查要处理的工作。如何让应用程序在启动并运行后启动计时器?

请您参考如下方法:

您可以为 AlwaysRunning 使用新的 ASP.Net 4 模式。这样就不会等待第一个请求开始

<applicationPools> 
     <add name="MyAppWorkerProcess" managedRuntimeVersion="v4.0"  
         startMode="AlwaysRunning" /> 
</applicationPools>  

参见:http://www.asp.net/learn/whitepapers/aspnet4