I have some code that uses a GT.Timer declared in a class like this:
In my constructor, I create a tick event handler:
```cs] myTimer.Tick += myTimer_Tick;[/code
Everything works fine unless I try to set the interval before I start it. If I try to set the interval like this:
```cs] myTimer.Interval = new TimeSpan(ScrollRate);[/code
and then start the timer, I never get an event fired.
Any thoughts?
@ Blue Hair Bob - How large is ScrollRate? The TimeSpan constructor overload takes a single argument in Ticks. Have you attempted using a TimeSpan object that is constructed using 5 arguments from day to millisecond?
I was shooting for ms: from 50 to 500.
The following code:
public partial class Program
{
GT.Timer MyTimer;
// This method is run when the mainboard is powered up or reset.
void ProgramStarted()
{
Debug.Print("Program Started");
MyTimer = new GT.Timer(500);
MyTimer.Tick += Timer_Tick;
MyTimer.Interval = new TimeSpan(0, 0, 0, 0, 1000);
MyTimer.Start();
}
void Timer_Tick(GT.Timer timer)
{
Debug.Print("Tick");
}
}
results in this output:
[quote=“FEZSpider”]Using mainboard GHI Electronics FEZSpider version 1.0
Program Started
Tick
Tick
Tick
Tick
Tick
Tick[/quote]
Yes, I have verified that does work.
I was trying to use
The parameter here is (long ticks). Obviously wrong is I pass in ms. But, even if I scale the value properly, it appears that the event never fires if set using this form of the call.
Thanks for the work around. Is this a bug?
@ Blue Hair Bob - The following code gave me the same Tick per second output:
public partial class Program
{
GT.Timer MyTimer;
// This method is run when the mainboard is powered up or reset.
void ProgramStarted()
{
Debug.Print("Program Started");
MyTimer = new GT.Timer(500);
MyTimer.Tick += Timer_Tick;
MyTimer.Interval = new TimeSpan(10000000);//new TimeSpan(0, 0, 0, 0, 1000);
MyTimer.Start();
}
void Timer_Tick(GT.Timer timer)
{
Debug.Print("Tick");
}
}
Also, due to an error in conversion on the fly, I was able to get a Tick per 10ms.
OK, thanks so much. I will try to figure out what I was doing wrong - or maybe just use what works and move on. You guys have the greatest support. Thanks again.