tags:

views:

122

answers:

4

Hi. I made a student check_list program thats using bluetooth adapter searches students cell phones bluetooth and checks that are they present or not and saves students informtion with date in table on data base.all them works gereat.But I want to make it automatic that I will put my program on some computer like works as an server and program will make search every lessons start time like 08.30 , 10.25 ...

My question is how to use timer? I know how to use timer but How can I use it on every lessons start time?I have table that includes start time of lessons. Also am I have to stop timer after search ends?And If I stop timer could I re-run timer againg?

And one additional question that how can I track that new students come or some body left class room?

A: 

You could periodically check the current time (like every 30 seconds with a simple timer) and if nothing happens, you sleep, if it's 10.25: start your bluetooth polling.

During class times you could just poll every 5 minutes to see if new students are there.

Tigraine
A: 

You could set the timer's Interval property to be the difference between the current time and the time for the next lesson; then reset the difference after that lesson is finished to be ready for the next. However, this has obvious pitfalls. What happens when you start/stop the timer? You will need to reset the Interval for the next lesson.

Or, you could make a timer which checks periodically if it is time to recheck the bluetooth devices and if it is time does so. It probably wouldn't need to be too accurate.

// Add your own DateTimes
DateTime[] times = new[] { new DateTime(2010, 4, 20, 16, 30,0,0), new DateTime(2010, 4, 20, 17, 0,0,0) };

Timer t = new Timer();
t.Interval = 30000; // 30 seconds, feel free to change

// Each 30 secs check to see if the _time_ is before one of the ones specified; if it is RunMethod()
t.Tick += (sender, e) => { if (times.Any(d => { DateTime dt = DateTime.Now; new DateTime(dt.Year, dt.Month, dt.Day, d.Hour, d.Minute, d.Second, d.Millisecond).CompareTo(dt) <= 0 })) RunMethod(); }
Callum Rogers
am I have to stop timer or not? Also if I am not stoping timer is will cause performance problem?Because this program will work on server maybe hole year.
Meko
A: 

I'd use Quartz.NET and schedule the jobs instead of messing with the timer...

kzen