I am trying to get the data from a 'DatePicker' called targetDate
and a couple of 'TextBox' called targetHour
and targetMinute
. I want to read whatever is in them every second. So I created a timer as follows:
System.Timers.Timer tmr = null;
private void SetTimer()
{
tmr = new System.Timers.Timer(1000);
tmr.AutoReset = true;
tmr.Elapsed += TimerEvent;
tmr.Enabled = true;
}
The timer is running fine and I am getting the data as well. For now, just for verification purposes I am displaying whatever I get from the targetDate
, targetHour
and targetMinute
to another TextBox differenceTime
inside the TimerEvent
.
Dispatcher.BeginInvoke(new ThreadStart(() => targetDT = targetDate.Text));
Dispatcher.BeginInvoke(new ThreadStart(() => targethh = Int32.Parse(targetHour.Text)));
Dispatcher.BeginInvoke(new ThreadStart(() => targetmm = Int32.Parse(targetMinute.Text)));
//temp = targetDT + " " + targethh + ":" + targetMinute;
Dispatcher.BeginInvoke(new ThreadStart(() => differenceTime.Text = targetDT + "-" + targethh));
The above code is working ok. My main question is, is there a better way to do this, without using the Dispatcher.BeginInvoke
? Also, but less important, if I try to use the temp
string to populate differenceTime
it doesn't work, why is that?