2

I need to check daily if there is some people late on there task, and send them emails if they are... what do i choose ? none of these seem made for that.

enter image description here

Antoine Pelletier
  • 3,164
  • 3
  • 40
  • 62
  • make a console application for mail sending code and schedule that with windows scheduler to run on specific time on daily. or you can also make a windows service. – Sain Pradeep Oct 07 '15 at 13:10
  • Windows scheduler ? Ok i'm gonna get informed. – Antoine Pelletier Oct 07 '15 at 13:12
  • @SainPradeep how am i going to retreive information of my web application and my database with windows scheduler, is it possible ? – Antoine Pelletier Oct 07 '15 at 13:15
  • 1
    Windows Task Scheduler is merely a mechanism to run a program on a schedule. So you're only limited to whatever the program can do. And if you managed to write an ASP.NET site that works with those tasks, then surely you can write a console program. The other option is writing a service (also a console app, but these run constantly) or embedding a [background task in ASP.NET](http://www.hanselman.com/blog/HowToRunBackgroundTasksInASPNET.aspx). Or if you're in the cloud, check out what your cloud hosting options are. The point is, do some research! – mason Oct 07 '15 at 13:18
  • first you need to make a new application with your logic and mail sending code. second , you need to schedule this new created application with the window scheduler to run on a specific time. window scheduler will not access your database. Your new application will interact with db. – Sain Pradeep Oct 07 '15 at 13:19
  • 1
    Ok thanks @mason , also, what if i use my global.asax ? There is an application_start event there, would it be a good place to START the task scheduler and let it run on the IIS along with the web application ? Hope i'm not mistaking. – Antoine Pelletier Oct 07 '15 at 13:36
  • 1
    You mean start the Windows Scheduled Task from Global.asax? Sure. But keep in mind that if the task gets unscheduled for any reason, the site isn't going to add code for you. Personally, if I were you I wouldn't do a scheduled task because now you need a new program and you need code to link the two together. I would look into one of the options listed in the background task link I provided earlier. Then you've got an all-in-one solution. – mason Oct 07 '15 at 13:39
  • True... I better go for the reel thing first or it'll be futur problems.... thanks a lot mason – Antoine Pelletier Oct 07 '15 at 13:45

1 Answers1

1

I used a background process, it's a thread that launch the function that sends reminder emails if necessary, then sleeps for 24h, hope it's good.

In Global.asax :

public class Global : System.Web.HttpApplication
{
    protected void Application_Start(object sender, EventArgs e)
    {
        Thread backGroundProcess = new Thread(BoucleInfini);
        backGroundProcess.Start();
    }
}

The thread :

    protected void BoucleInfini()
    {
        while (0==0)
        {
            BLL.Rappel.RetardCheckUp(System.Web.Hosting.HostingEnvironment.MapPath("~/_inc/courriels"));

            Thread.Sleep(1000 * 60 * 60 * 24);
        }
    }

Using web site mason gave me : http://www.hanselman.com/blog/HowToRunBackgroundTasksInASPNET.aspx

EDIT

This is wrong...

Just use windows task scheduler, it's on almost every windows servers.

Antoine Pelletier
  • 3,164
  • 3
  • 40
  • 62
  • Haha i was so dumb, this answer is miles away from a good solution, simply use managed task as being discussed with mason, because what i programmed works only if there is enough traffic in the site. If no one connects today... no reminders sent. – Antoine Pelletier Nov 22 '16 at 20:37