Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
491 views
in Technique[技术] by (71.8m points)

c# - How to execute a method in Asp.net MVC for every 24 hours

I have method in MVC like

 public void Sendmails()
 {
     //sending mails for every 24 hours.
 }

Can I schedule above method to execute for every 24 hours. I know we can set schedule with sql server agent and windows task scheduler . But due to some issues i want to execute current dll only, is this possible in MVC?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

Possible? Perhaps, with a bit of hacking on invoking tasks and background threads. Reliable? Not in the slightest.

A web application is essentially a request-response system. The application receives a request, performs its logic, and returns a response. Beyond that, it's idle. And it's at the mercy of the web server to be entirely unloaded from memory if the web server wants to use or free up that memory.

To run something periodically without user interaction (that is, without a request to initiate it), a web application isn't what you want. Instead, you're looking for either a Windows Service or perhaps a simple Console Application scheduled to run at regular intervals by the host system's scheduling software (Windows Task Scheduler, cron, etc.).

These applications can easily share code, of course. They can be in the same solution and have references to the same class libraries. Indeed, the application layer of your code should always be as thin and light as possible and all of the meaningful code should be in shared business logic assemblies. Then any application (web application, windows service, console application, etc.) can simply reference those shared assemblies and invoke the same logic.

Furthermore, multiple running applications can also easily share the same data. They can both connect to the same database (using shared data access logic, of course) and essentially be otherwise identical representations of centralized logic which happens to be invoked by separate application instances.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...