Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/266.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 为什么分派器委托在WinRT中工作?_C#_Windows Phone 7_Windows 8_Windows Runtime_Microsoft Metro - Fatal编程技术网

C# 为什么分派器委托在WinRT中工作?

C# 为什么分派器委托在WinRT中工作?,c#,windows-phone-7,windows-8,windows-runtime,microsoft-metro,C#,Windows Phone 7,Windows 8,Windows Runtime,Microsoft Metro,下面的代码适用于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 = n

下面的代码适用于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(Metro)中出现错误

错误部分:

  timer.Tick += timer_Ticker;
错误消息:

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

但它又不起作用了,为什么以及如何解决它(

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

    private void timer_Ticker(object sender, object e)
    {
        txtTime.Text = get24hour();
    }
timer.Tick+=新的事件处理程序(timer\u Tick);
私有无效计时器(对象发送方,对象e)
{
}

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

private void timer_Tick(object sender, object e)
{
}