Reputation: 355
I have this code:
public void StartTimer()
{
var timer = new DispatcherTimer();
timer.Tick += Something;
timer.Interval = new TimeSpan(0, 0, 0, 3);
timer.Start();
}
private async void Something()
{
//code goes here....
}
The problem is that I get this error:
No overload for 'Something' matches delegate 'System.EventHandler'
My question is probably basic: why I get this error and how can I fix it...
Upvotes: 0
Views: 64
Reputation: 504
Try This
public void StartTimer()
{
var timer = new DispatcherTimer();
timer.Tick += Something;
timer.Interval = new TimeSpan(0, 0, 0, 3);
timer.Start();
}
private async void Something(Object sender, EventArgs e)
{
//code goes here....
}
Upvotes: 0
Reputation: 68660
The property Tick
is of type EventHandler
.
The signature of EventHandler
is:
public delegate void EventHandler(
Object sender,
EventArgs e
)
Which means your Something
method must match this signature. Change it to:
public void Something(Object sender, EventArgs e) { ... }
Alternatively, if you can't change the signature of that method, you can create a new delegate that calls your method.
timer.Tick += (s, e) => Something();
Upvotes: 3
Reputation: 101662
The DispatcherTimer.Tick
event expects a handler that takes an object
and an EventArgs
argument:
private void Something(object o, EventArgs e)
{
// implementation
}
Upvotes: 1
Reputation: 171178
The signature of Something does not match that specific event. Look into the documentation for that event to see how it's done.
Upvotes: 0