我已经从分配文本框中的字符串值日期时间variable.It的目的是作为一个标志,告诉myTimer对象时停止已达到存储在workDt的时候,(日期时间变量)。
当前实现我曾尝试是下面的,我在那里建立了一个if..else语句来检查计时器的当前时间等于什么是在文本框中输入,但它不会触发计时器停止。
我设置的“如果”声明一个破发点,时间值被存储在workDt但不触发计时器停止。
任何人都可以看到一个缺陷在我的实现或替代解决方案提供什么建议吗?
private void startBtn_Tap(object sender, System.Windows.Input.GestureEventArgs e)
{
string wrkString;
string rstString;
//Assign text box time string to string variables.
wrkString = wrkTbx.Text;
rstString = restTbx.Text;
//Assign text box string value to a date time variable.
DateTime workDt = DateTime.ParseExact(wrkString.Replace(": ", ":").Replace(" :", ":"), "HH:mm:ss:fff", CultureInfo.InvariantCulture);
DateTime restDt = DateTime.ParseExact(rstString.Replace(": ", ":").Replace(" :", ":"), "HH:mm:ss:fff", CultureInfo.InvariantCulture);
StopGoCvs.Background = new SolidColorBrush(Colors.Green);
hornElmt.Play();
// // set up the timer
myTimer = new DispatcherTimer();
myTimer.Interval = new TimeSpan(0, 0, 0, 0, 1);
myTimer.Tick += myTimer_Tick;
//tell timer to stop when it has reached the allocated work time.
if(myTimer.Interval != workDt.TimeOfDay)
{
// start both timers
myTimer.Start();
myStopwatch.Start();
}
else
{
myTimer.Stop();
myStopwatch.Stop();
}
}