如何在Asp.net MVC执行方法,每24小时 [英] How to execute a method in Asp.net MVC for every 24 hours

查看:127
本文介绍了如何在Asp.net MVC执行方法,每24小时的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在MVC方法如

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

我可以安排上面的方法来执行每24小时。
我知道我们可以设置日程安排与SQL Server代理和Windows任务调度。
但由于一些问题,我想只执行当前的dll,这可能在MVC?

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?

推荐答案

可能吗?也许,有位黑客上调用任务和后台线程。的可靠?的没有丝毫。

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

一个Web应用程序本质上是一个请求 - 响应系统。该应用程序接收到一个请求,执行它的逻辑,并返回一个响应。除此之外,它的闲置。而且它在Web服务器的摆布如果Web服务器要使用或释放​​该内存。要完全从内存中卸载

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.

要无需用户交互定期运行的东西(也就是说,不启动它的请求),Web应用程序是不是你想要的。相反,你要找的不是一个Windows服务或者一个简单的控制台应用程序计划在主机系统的调度软件(Windows任务计划程序,cron的,等等)。定期运行

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.).

这些应用程序可以轻松地共享,当然code。它们可以是在相同的溶液中,具有对同一类库引用。事实上,你的code的应用层应始终作为轻薄越好,所有有意义的code应该是共享的业务逻辑组件。然后,任何应用程序(Web应用程序,窗口服务,控制台应用程序等),可以直接引用这些共享组件和调用相同的逻辑。

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.

此外,多个运行的应用程序还可以轻松地共享相同的数据。它们既可以连接到相同的数据库(使用共享数据访问逻辑,当然),并且基本上是否则的相同的恰好由单独的应用程序的实例调用集中逻辑重新presentations

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.

这篇关于如何在Asp.net MVC执行方法,每24小时的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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