No overload for 'method' corresponds to delegate 'System.EventHandler'

I am trying to create a program that after pressing a button every 5 seconds will perform a function (OnTimed).

Below is the code:

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 shows an error:

'No overload for' method 'corresponds to delegate' System.EventHandler '

+5
source share
6 answers

The signature of the event-handler method is not compatible with the delegation type.

Subscribers to the DispatcherTimer.Tickevent must be EventHandlerwhich is declared as:

public delegate void EventHandler(object sender, EventArgs e);

Try this instead:

void OnTimed(object sender, EventArgs e)
{
   ...
}
+11
source

If you are using Windows 8.1 for Windows, you will need the following

private void OnTimed(object sender, object e) {
      // You Code Here
 }
+2

OnTimed :

 private void OnTimed(object sender, EventArgs e)
 {
     // Do something
 }
+1

Dispatcher.Tick EventHandler:

EventHandler Tick;

, EventHandler :

void OnTimed(object sender, EventArgs e)

void OnTimed(object sender, ElapsedEventArgs e)

, - System.Timers.Timer.Elapsed :

public event ElapsedEventHandler Elapsed

public delegate void ElapsedEventHandler(
    Object sender,
    ElapsedEventArgs e
)
0

, , - :

timer.Tick += new EventHandler(Method);

public void Method(object sender, EventArgs e)
{
//Do Something
}

.

: timer.Tick + = Method;

timer.Tick += Method;

public void Method(object sender, EventArgs e)
{
//Do Something
}

, !

0

In my case, I used my own winforms control to recognize digitalPersona fingerprints.

When I tried to overload the "OnComplete" method, it came up with "No overload ..."

private void FingerprintVerificationControl_OnComplete(object control, DPFP.FeatureSet featureSet, DPFP.Gui.EventHandlerStatus eventHandlerStatus)

Here is how it looked.

I looked at the assembly and I noticed that the third parameter bound the 'ref' keyword to it. I added it to my code and it worked:

private void FingerprintVerificationControl_OnComplete(object control, DPFP.FeatureSet featureSet, ref DPFP.Gui.EventHandlerStatus eventHandlerStatus)
-1
source

All Articles