I am trying to build a program that, once the button was click, every 5 second will perform the function (OnTimed).
我正在尝试构建一个程序,一旦按下按钮,每5秒钟将执行该功能(OnTimed)。
Below is the code so far:
以下是目前的代码:
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:
当我运行代码时,它显示错误:
"No overload for 'method' matches delegate 'System.EventHandler'
“'方法'没有重载匹配委托'System.EventHandler'
6 个解决方案
#1
11
The signature of the event-handler method isn't compatible with the delegate type.
事件处理程序方法的签名与委托类型不兼容。
Subsribers to the DispatcherTimer.Tick
event must be of the EventHandler
delegate type, which is declared as:
DispatcherTimer.Tick事件的订阅者必须是EventHandler委托类型,声明为:
public delegate void EventHandler(object sender, EventArgs e);
Try this instead:
试试这个:
void OnTimed(object sender, EventArgs e)
{
...
}
#2
2
If you using Windows phone 8.1 then you need the following
如果您使用Windows Phone 8.1,则需要以下内容
private void OnTimed(object sender, object e) {
// You Code Here
}
#3
1
Method OnTimed has to declared like this:
方法OnTimed必须像这样声明:
private void OnTimed(object sender, EventArgs e)
{
// Do something
}
#4
0
Dispatcher.Tick is simple EventHandler:
Dispatcher.Tick是简单的EventHandler:
public event EventHandler Tick;
公共事件EventHandler Tick;
So EventHandler parameters should be:
所以EventHandler参数应该是:
void OnTimed(object sender, EventArgs e)
Not the
void OnTimed(object sender, ElapsedEventArgs e)
Looks like you a bit overlooked around the System.Timers.Timer.Elapsed event which is:
看起来你有点忽略了System.Timers.Timer.Elapsed事件,它是:
public event ElapsedEventHandler Elapsed
public delegate void ElapsedEventHandler(
Object sender,
ElapsedEventArgs e
)
#5
0
I know it might be a little bit late, but i just wanted to throw in a bit more for anyone with this problem:
我知道这可能有点晚了,但我只是想为这个问题的任何人多投入一点:
timer.Tick += new EventHandler(Method);
public void Method(object sender, EventArgs e)
{
//Do Something
}
solves the Problem.
解决问题。
It can also be written like this: timer.Tick += Method;
它也可以这样写:timer.Tick + = Method;
timer.Tick += Method;
public void Method(object sender, EventArgs e)
{
//Do Something
}
Hope it helps!
希望能帮助到你!
#6
-1
In my case I was using a custom winforms control for digitalPersona fingerprint recognition.
在我的情况下,我使用自定义winforms控件进行digitalPersona指纹识别。
When I tried to overload the 'OnComplete' method it would come up with 'No overload...'
当我试图重载“OnComplete”方法时,它会提出“没有超载......”
private void FingerprintVerificationControl_OnComplete(object control, DPFP.FeatureSet featureSet, DPFP.Gui.EventHandlerStatus eventHandlerStatus)
This is what it looked like.
这就是它的样子。
I looked into the assembly and I noticed that third parameter had the 'ref' keyword attached to it. I added it in my code and it worked:
我查看了程序集,我注意到第三个参数附加了'ref'关键字。我在我的代码中添加了它并且它有效:
private void FingerprintVerificationControl_OnComplete(object control, DPFP.FeatureSet featureSet, ref DPFP.Gui.EventHandlerStatus eventHandlerStatus)
#1
11
The signature of the event-handler method isn't compatible with the delegate type.
事件处理程序方法的签名与委托类型不兼容。
Subsribers to the DispatcherTimer.Tick
event must be of the EventHandler
delegate type, which is declared as:
DispatcherTimer.Tick事件的订阅者必须是EventHandler委托类型,声明为:
public delegate void EventHandler(object sender, EventArgs e);
Try this instead:
试试这个:
void OnTimed(object sender, EventArgs e)
{
...
}
#2
2
If you using Windows phone 8.1 then you need the following
如果您使用Windows Phone 8.1,则需要以下内容
private void OnTimed(object sender, object e) {
// You Code Here
}
#3
1
Method OnTimed has to declared like this:
方法OnTimed必须像这样声明:
private void OnTimed(object sender, EventArgs e)
{
// Do something
}
#4
0
Dispatcher.Tick is simple EventHandler:
Dispatcher.Tick是简单的EventHandler:
public event EventHandler Tick;
公共事件EventHandler Tick;
So EventHandler parameters should be:
所以EventHandler参数应该是:
void OnTimed(object sender, EventArgs e)
Not the
void OnTimed(object sender, ElapsedEventArgs e)
Looks like you a bit overlooked around the System.Timers.Timer.Elapsed event which is:
看起来你有点忽略了System.Timers.Timer.Elapsed事件,它是:
public event ElapsedEventHandler Elapsed
public delegate void ElapsedEventHandler(
Object sender,
ElapsedEventArgs e
)
#5
0
I know it might be a little bit late, but i just wanted to throw in a bit more for anyone with this problem:
我知道这可能有点晚了,但我只是想为这个问题的任何人多投入一点:
timer.Tick += new EventHandler(Method);
public void Method(object sender, EventArgs e)
{
//Do Something
}
solves the Problem.
解决问题。
It can also be written like this: timer.Tick += Method;
它也可以这样写:timer.Tick + = Method;
timer.Tick += Method;
public void Method(object sender, EventArgs e)
{
//Do Something
}
Hope it helps!
希望能帮助到你!
#6
-1
In my case I was using a custom winforms control for digitalPersona fingerprint recognition.
在我的情况下,我使用自定义winforms控件进行digitalPersona指纹识别。
When I tried to overload the 'OnComplete' method it would come up with 'No overload...'
当我试图重载“OnComplete”方法时,它会提出“没有超载......”
private void FingerprintVerificationControl_OnComplete(object control, DPFP.FeatureSet featureSet, DPFP.Gui.EventHandlerStatus eventHandlerStatus)
This is what it looked like.
这就是它的样子。
I looked into the assembly and I noticed that third parameter had the 'ref' keyword attached to it. I added it in my code and it worked:
我查看了程序集,我注意到第三个参数附加了'ref'关键字。我在我的代码中添加了它并且它有效:
private void FingerprintVerificationControl_OnComplete(object control, DPFP.FeatureSet featureSet, ref DPFP.Gui.EventHandlerStatus eventHandlerStatus)