I'm developing a simple app that checks the DB every 60 secs. I use System.Threading.TimerCallback
to do that, but, when I run the app, it only ticks once.
Here is the code:
private void Form1_Load(object sender, EventArgs e)
{
// Create the delegate for the Timer type.
System.Threading.TimerCallback timeCB = new System.Threading.TimerCallback(d);
// Establish timer settings.
System.Threading.Timer t = new System.Threading.Timer(
timeCB, // The TimerCallback delegate object.
null, // Any info to pass into the called method (null for no info).
0, // Amount of time to wait before starting (in milliseconds).
1000); // Interval of time between calls (in milliseconds).
}
void m(object o)
{
System.Media.SystemSounds.Hand.Play();
SReminderEntities ctx = new SReminderEntities();
var jobs = (from m in ctx.Messages
select m).ToList();
var seljobs = from j in jobs
where j.RemindeTime.Date == DateTime.Now.Date
&& j.RemindeTime.Hour == DateTime.Now.Hour
&& j.RemindeTime.Minute == DateTime.Now.Minute
select j;
foreach (var j in seljobs)
{
// SendGmail("iReminder", j.Text, new string[] { j.User.Email }, "iReminderSender@Gmail.com");
//this.sendSMS(j.User.Mobile, j.Text);
System.Media.SystemSounds.Hand.Play();
}//foreach
}
void d(object o)
{
MessageBox.Show("Test");
}
When I call d
it works, but m
just runs once. What is the problem and how can I solve it? Thank you.