简体   繁体   English

每天早上08:00使用ASP.NET C#显示一些消息

[英]Show some message every day at 08:00 AM with ASP.NET C#

I want to read my database get values, change my old message with new value and then show this newly message. 我想读取数据库中的值,用新值更改旧消息,然后显示新消息。 I want to do this reading job at everyday 08:00. 我想每天08:00做这份阅读工作。 How can I know if clock is 08:00 AM? 我怎么知道时钟是08:00 AM? Need to control every second? 需要每秒控制一次吗? or what else? 还是什么?

The key thing to note here is that you don't actually need to do this at 8am - you need to do it when the application is in use at 8am or the first time the application is in use after 8am - if, that is, you want to do this solely within your ASP.NET application. 这里要注意的关键是您实际上不需要在上午8点执行此操作-您需要在上午8点使用该应用程序时在上午8点之后首次使用该应用程序时执行此操作-如果,您只想在ASP.NET应用程序中执行此操作。

You need to track when the message was last updated. 您需要跟踪消息的最新更新时间。

In ASP.NET in a suitable application startup event, call the update method - which should check to see if the value needs updating - and then set a timer (its been 5 years since I wrote the code to do this last, options will have changed) for the "next" 8am - when the timer fires, call your update method, set the timer again. 在ASP.NET中合适的应用程序启动事件中,调用update方法-该方法应检查值是否需要更新-然后设置一个计时器(自从我编写代码完成此操作已经过去5年了,选项将具有更改)(对于“下一个”上午8点)-计时器启动时,请调用您的更新方法,然后再次设置计时器。 So, if the app starts it will update if required, if its running the update will happen. 因此,如果应用程序启动,它将在需要时进行更新,如果运行,则将进行更新。

If you have more access to the server then create a windows service to do the update. 如果您具有对服务器的更多访问权限,则创建Windows服务以进行更新。

There are several options in between these two - create a page or a web service to trigger the update logic within the ASP.NET application and then use an external timer to open the page/call the web service at the scheduled time. 这两者之间有多个选项-创建页面或Web服务以触发ASP.NET应用程序中的更新逻辑,然后使用外部计时器在计划的时间打开页面/调用Web服务。 The most appropriate solution depends on your hosting enviroment and the other resources available to you. 最合适的解决方案取决于您的托管环境和其他可用资源。

您可以创建Windows服务并将其安排在每天所需的时间。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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