为什么调度程序计时器委托在 WinRT 中工作

本文关键字:WinRT 工作 调度程序 计时器 为什么 | 更新日期: 2023-09-27 18:37:24

下面的代码适用于Windows Phone 7

    private void ShowTime()
    {
        txtTime.Text = get24hour();
        //display the Date and week.
        DateTime nowtime = DateTime.Now;
        txtWeek.Text = nowtime.DayOfWeek.ToString();
        txtDate.Text = nowtime.Date.ToString("MM/dd");   
        //create timer to fresh to time
        DispatcherTimer timer = new DispatcherTimer();
        timer.Interval = TimeSpan.FromMinutes(1);
        timer.Tick += timer_Ticker;
        timer.Start();        
    }
    private void timer_Ticker(object sender, EventArgs e)
    {
        txtTime.Text = get24hour();
    }
    private string get24hour()
    {
        return DateTime.Now.ToString("HH:mm");
    }

但在 WinRT (地铁) 中出错

错误部分:

  timer.Tick += timer_Ticker;

错误信息:

  No overload for 'timer_Ticker' matches delegate 'System.EventHandler<object>' 

我做什么
我尝试将代码更改为

    private void timer_Ticker()
    {
        txtTime.Text = get24hour();
    }

结果
但它又不行了,为什么以及如何解决它?:(

为什么调度程序计时器委托在 WinRT 中工作

timer.Tick += new EventHandler<object>(timer_Tick); 
private void timer_Tick(object sender, object e)
{
}

请参阅此链接

我阅读了 msdn 并将委托方法更改为下面,它可以工作:

    private void timer_Ticker(object sender, object e)
    {
        txtTime.Text = get24hour();
    }