views:

93

answers:

4

i have a list of events "Appointments" in my database, like at 3:00pm etc, and they have irregular intervals like one after 15 mins and next after 30 mins and next after 25 mins. One way is that i run a thread/timer that checks the database every minute whether it is the minute of next appointment or not.. i want some other mechanism by which i can trigger an alert/event/action on the next saved time that is in my database... how to do it...

+2  A: 

You should take a look at Quartz.NET.

From the Features of Quartz.Net:

Quartz.NET can run embedded within another free standing application

Austin Salonen
i need to implement it in C# with in my application, other standalone or any other kind of systems wont work...
Junaid Saeed
Quartz.NET can also run within your application as it's a library for scheduling.
Marko Lahma
A: 

Timer Class

Provides a mechanism for executing a method at specified intervals. This class cannot be inherited.

recursive
A: 

You can use the Timer object. You'll specify a time and a callback function that will be used when the event is triggered.

You can initialize the timer to trigger the event for the first interval. When the event is consumed you can reset the timer for the next interval and so on.

Adrian Faciu
timer is periodic man...
Junaid Saeed
+1  A: 

Get the date/time of the next appointment in the database, subtract from that DateTime.Now in order to get a TimeSpan, and then use that timespan to fire the timer once, similar to this:

class MainClass
{
    public static void FireTimerAt(DateTime next)
    {
        TimeSpan waitTime = next - DateTime.Now;

        new Timer(delegate(object s) {
                        Console.WriteLine("{0} : {1}",
                        DateTime.Now.ToString("HH:mm:ss.ffff"), s);
                    }
              , null, waitTime, new TimeSpan(-1));
    }
}
esac