我想創建一個Windows窗體應用程序,我想實現一個計時器。解決錯誤:'計時器'是'System.Windows.Forms.Timer'和'System.Timers.Timer'之間的歧義參考
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'
而且我不確定如何解決這個錯誤。一旦計時器結束,我打算提醒用戶注意事件。我不想讓計時器出現在表單上。