0

I am working with an ASP site which requires a "reminder" email to be sent out every x, y and z minutes. I have attempted to start a timer upon an event (like a button click or page load) but this proved to be unreliable as the timers would be disposed of when the server performed an automatic backup or when the aspx.cs file was updated.

My new idea is to have a timer constantly running (a check is performed on a page load which ensures its running) and, when it elapses, it checks to see if either x, y or z minutes have elapsed. So if y elapses, it needs to send out a "reminder" email and then restart y's timer.

void ParentTimer_Elapsed(object sender, ElapsedEventArgs e)
{
    foreach(Timer childTimer in ChildTimerList)
    {
        if(childTimer.Enabled == false) // And therefore has elapsed
        {
            sendReminderEmail(childTimer);
            childTimer = checkAndSetCorrectInterval(childTimer);
            childTimer.AutoReset = false;
            childTimer.Enabled = true;
        }
    }
}

The list ChildTimerList would obviously contain x, y and z.

Can anybody forsee me running into any problems with this, or are there any better ways to approach it? My perfect solution would be a timer running costantly which doesn't need to be started upon an event but I don't think this is possible with ASP.

Furthermore, where should I initialise my parent timer and childlist variables? In a class within the App_Code folder or, statically, in a code-behind aspx.cs page?

Thanks in advance.

EDIT:

Yes, I do mean ASP.NET... :)

3
  • 1
    @giddy ASP with C# can't be classic ASP so the only meaning is ASP.NET :) Commented Jul 5, 2011 at 9:51
  • @shadow yea I was checking before I hit edit, since I only skimmed the question, and then someone had edited it already. SO is so fast paced! :) Commented Jul 5, 2011 at 10:53
  • @giddy yep that someone was me. ;) Commented Jul 5, 2011 at 10:59

1 Answer 1

3

I would probably implement this with a simple console application (responsible for sending e-mails) and Task Scheduler in Windows (responsible for running the application on a schedule). Keep it simple. And robust.

Edit: Provided that you are in control of the server - it will probably not be the best solution in a shared hosting environment where you're only allowed to run web apps.

Sign up to request clarification or add additional context in comments.

3 Comments

+1, use a service for that and just let ASP.NET communicate with it.
Windows Service is ideal for such things - don't have to log in into the server to have it working..
Thanks for that guys. I will consider a better approach. Is there any material you can provide so I can read more about your suggestions?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.