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.

NAV Timer Control Add-ins

2 thoughts on “More on the NAV Timer Control Add-in

  1. wakestar says:

    Hi there
    I’m the one who wrote the mibuso article back in 2011.
    My issue with the timer was in NAV2009.
    In NAV2013 I haven’t tried the same thing again but maybe you can tell me wether
    the timer add-in still throws an null reference exception when you change the company or language in NAV (as I explained in my mibuso article).

    1. I think that exception is caused by the timer.Start() method that is executed even if timer.Interval is zero.

Leave a Reply

%d bloggers like this: