Hi All,
Apologies for the noobish question - i'm utilising a couple of controls to kick off a process within my form - in short i have a DateTimePicker, Timer, CheckBox. The user enters the time they wish the process to run in the DateTimePicker (which has its format set to Time), ticks the CheckBox, which kicks off the Timer with an interval of 900ms. The Timer_Tick event checks if the DateTimePicker.Value is now and if so, does something. My problem is that either the DateTimePicker.Value never equals now or that the Timer_Tick event is never actually called.
I welcome any input into better ways of accomplishing this, i am conscious that polling for the time every second is a drain of resources but the only alternative i can see is a service which is overkill.
Code as follows:
Apologies for the noobish question - i'm utilising a couple of controls to kick off a process within my form - in short i have a DateTimePicker, Timer, CheckBox. The user enters the time they wish the process to run in the DateTimePicker (which has its format set to Time), ticks the CheckBox, which kicks off the Timer with an interval of 900ms. The Timer_Tick event checks if the DateTimePicker.Value is now and if so, does something. My problem is that either the DateTimePicker.Value never equals now or that the Timer_Tick event is never actually called.
I welcome any input into better ways of accomplishing this, i am conscious that polling for the time every second is a drain of resources but the only alternative i can see is a service which is overkill.
Code as follows:
VB.NET:
Private Sub Timer_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer.Tick
If ScheduleDateTimePicker.Value = Now Then
ProcessEnabledCheckBox.Checked = True
End If
End Sub
Private Sub EnableScheduledRunCheckBox_CheckStateChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles EnableScheduledRunCheckBox.CheckStateChanged
If EnableScheduledRunCheckBox.Checked = True Then
Timer.Enabled = True
Timer.Start()
ElseIf EnableScheduledRunCheckBox.Checked = False Then
Timer.Stop()
Timer.Enabled = False
End If
End Sub