Frage

I don't know where to start or what to use to solve this 2 problems:

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

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

War es hilfreich?

Lösung

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.

Andere Tipps

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

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

Pretty late but you should consider lookint at http://hangfire.io/. Its an amazing library and provides a full fletched UI to manage jobs :)

Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top