我想弄清楚一個調度計時器是如何工作的,所以我可以實現它到我的程序中,我遵循網站上的確切說明並尋找堆棧溢出的答案。人們說,他們的問題是固定的,但我有非常相似的代碼,它不會工作...調度計時器不會工作
的錯誤是:
無過載爲「timer_Tick」匹配下放「事件處理<對象>」
我該怎麼辦?
public MainPage()
{
this.InitializeComponent();
DispatcherTimer timer = new DispatcherTimer();
timer.Interval = TimeSpan.FromSeconds(1);
timer.Tick += timer_Tick;
timer.Start();
}
void timer_Tick(EventArgs e)
{
TimeRefresh();
}
仍然無法工作。同樣的錯誤 – Albert
我使用DispatchTimer,但是當我使用'System.Windows.Threading.DispatcherTimer'它說'名字空間'System.Windows'中不存在類型或命名空間名稱'線程'(你是否缺少程序集引用? )' – Albert
你幾乎在那裏。只需將'using System.Windows.Threading;'添加到您的類的頂部。 –