我正在尝试创建一个 Windows 窗体应用程序,并且我想实现一个计时器。
public void timerStart()
{
DateTime now = DateTime.Now;
DateTime finish = base.taskEndDate;
finish = finish.AddHours(_appointmentTime.Hours); //_appointmentTime is a user defined value.
finish = finish.AddMinutes(_appointmentTime.Minutes);
finish = finish.AddMilliseconds(_appointmentTime.Milliseconds);
//Calculating the milliseconds left till task ends.
int daysLeft = finish.Day - now.Day;
int hoursLeft = finish.Hour - now.Hour;
int minsLeft = finish.Minute - now.Minute;
int secLeft = finish.Second - now.Second;
int milLeft = finish.Millisecond - now.Millisecond;
//Preparing to Start the timer.
TimeSpan end = new TimeSpan(daysLeft, hoursLeft, minsLeft, secLeft, minsLeft);
MessageBox.Show(end.ToString());
double x = end.TotalMilliseconds;
System.Timers.Timer _timer = new Timer(x);
}
是我如何定义我的方法但我收到错误
'Timer' is an ambiguous reference between 'System.Windows.Forms.Timer' and 'System.Timers.Timer'
而且我不确定如何解决该错误。一旦计时器结束,我计划制作一个提醒用户的事件。我不希望计时器出现在表单上。