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