“方法"没有重载匹配委托“System.EventHandler" [英] No overload for 'method' matches delegate 'System.EventHandler'
本文介绍了“方法"没有重载匹配委托“System.EventHandler"的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在尝试构建一个程序,一旦单击按钮,每 5 秒就会执行一次该功能 (OnTimed).
I am trying to build a program that, once the button was click, every 5 second will perform the function (OnTimed).
以下是目前的代码:
private void bntCapture_Click(object sender, RoutedEventArgs e)
{
DispatcherTimer t1 = new DispatcherTimer();
t1.Interval = TimeSpan.FromMilliseconds(5000);
t1.IsEnabled = true;
t1.Tick += new EventHandler(OnTimed);
t1.Start();
}
void OnTimed(object sender, ElapsedEventArgs e)
{
imgCapture.Source = imgVideo.Source;
System.Threading.Thread.Sleep(1000);
Helper.SaveImageCapture((BitmapSource)imgCapture.Source);
}
当我运行代码时,它显示错误:
When i run the code, it show the error:
'method' 没有重载匹配委托'System.EventHandler'
"No overload for 'method' matches delegate 'System.EventHandler'
推荐答案
事件处理程序方法的签名与委托类型不兼容.
The signature of the event-handler method isn't compatible with the delegate type.
DispatcherTimer 的订阅者.Tick
事件必须属于 EventHandler
委托类型,声明为:
Subsribers to the DispatcherTimer.Tick
event must be of the EventHandler
delegate type, which is declared as:
public delegate void EventHandler(object sender, EventArgs e);
试试这个:
void OnTimed(object sender, EventArgs e)
{
...
}
这篇关于“方法"没有重载匹配委托“System.EventHandler"的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文