I am developing an application in windows 8 Visual studio 11, and I want to define an event handler for a DispatcherTimer instance as below:
public sealed partial class BlankPage : Page
{
int timecounter = 10;
DispatcherTimer timer = new DispatcherTimer();
public BlankPage()
{
this.InitializeComponent();
timer.Tick += new EventHandler(HandleTick);
}
private void HandleTick(object s,EventArgs e)
{
timecounter--;
if (timecounter ==0)
{
//disable all buttons here
}
}
.....
}
But I get the following Error :
Cannot implicitly convert type 'System.EventHandler' to 'System.EventHandler<object>'
I am a novice developer to widows 8 apps.
Would you please help me ?
Pull the tape slowly and switch the ticker-timer on at the start signal. Switch it off at the stop signal. Count the number of dot-to-dot spaces between the start and the stop. That is the time between the signals, measured in ticks .
The Stopwatch. ElapsedTicks is measuring a "tick" in terms of the stopwatch, which is a length of time of 1 second/ Stopwatch.
When the interval elapses in timer control, the Elapsed event has occurred. A tick event is used to repeat the task according to the time set in the Interval property. It is the default event of a timer control that repeats the task between the Start() and Stop() methods.
almost had it :) You don't need to instantiate a new eventhandler object, you only need to point to the method that handles the event. Hence, an eventhandler.
int timecounter = 10;
DispatcherTimer timer = new DispatcherTimer();
public BlankPage()
{
this.InitializeComponent();
timer.Tick += timer_Tick;
}
protected void timer_Tick(object sender, object e)
{
timecounter--;
if (timecounter == 0)
{
//disable all buttons here
}
}
Try to read up on delegates to understand events Understanding events and event handlers in C#
Your code is expecting HandleTick to have two Object params. Not an object param and an EventArg param.
private void HandleTick(object s, object e)
NOT
private void HandleTick(object s,EventArgs e)
This is a change that took place for Windows 8.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With