Reputation: 1588
I don't know where to start or what to use to solve this 2 problems:
I have a User model and a Event model (football match, karts race, etc). And I want that when a user creates a new Event send and email to other users.
I need "something" that checks let's say every 15 minutes, delete all the Events that are already over (Example: Events from yesterday) from the database.
I know that in Ruby on Rails, there are Observers and Background Workers, there is something like that in MVC3 ? or there are other ways of accomplish that ?
Upvotes: 2
Views: 5153
Reputation: 1117
Pretty late but you should consider lookint at http://hangfire.io/. Its an amazing library and provides a full fletched UI to manage jobs :)
Upvotes: 0
Reputation: 8616
It's true that there are risks. But sometimes we have to take this option, especially when we are on a tight schedule to implement a job queue. If you are not familier with windows services, you need to learn about those things.
Following worked for me, (.NET 4.5.2). Once I invoke InitiateLongRunningProcess
controller, it initiate a longrunning process and return to view without waiting for the longrunning job.
public ActionResult InitiateLongRunningProcess(Emails emails)
{
if (ModelState.IsValid)
{
HostingEnvironment.QueueBackgroundWorkItem(ct => LongRunningProcessAsync(emails.Email));
return RedirectToAction("Index", "Home");
}
return View(user);
}
Read this great article from Hanselman HowToRunBackgroundTasksInASPNET
Upvotes: 0
Reputation: 1038830
Those kind of tasks are better suited to be done from a separate process such as a Windows service. You should avoid using background tasks in your web applications.
Upvotes: 3
Reputation: 20556
I would suggest using Quartz.net as a robust solution because of being full-featured, open source job scheduling system that can be used from smallest apps to large scale enterprise systems.
More Info: Job Scheduler with asp.net mvc
Upvotes: 2