In the previous post I showed a change that I did to Freedy’s timer control. That was not the end of my problems. First I had the timer stop in some cases where I did not want that and in other cases I wanted to close the page in the Event Trigger.
Duilio Tacconi, a Microsoft Dynamics NAV Support Engineer found a post in Mibuso. After reading that I removed all the thread handling and created a new timer control without. In another page I still wanted the thread handling, that is, I wanted the timer to stop if I started a subpage or a process. That solved my first problem.
The second problem appeared when I tried to close a page from the AddInEvent on the page. Freddy’s code did not allow this. The original code is
[code lang=”csharp”] /// <summary>
/// Timer tick handler – raise the Service Tier Add-In Event
/// </summary>
void timer_Tick(object sender, EventArgs e)
{
// Stop the timer while running the add-in Event
timer.Stop();
// Invoke event
this.RaiseControlAddInEvent(this.count++, "");
// Restart the timer
timer.Start();
}[/code]
and I changed it to
[code lang=”csharp”] /// <summary>
/// Timer tick handler – raise the Service Tier Add-In Event
/// </summary>
void timer_Tick(object sender, EventArgs e)
{
// Stop the timer while running the add-in Event
timer.Stop();
// Invoke event
this.RaiseControlAddInEvent(this.count++, "");
// Restart the timer
if (timer.Interval > 0)
{
timer.Start();
}
}[/code]
to make sure that the add-in did not try to start the timer if I set the interval to zero.