Personalized Community is here!
Quickly customize your community to find the content you seek.
Choose your path Increase your proficiency with the Dynamics 365 applications that you already use and learn more about the apps that interest you. Up your game with a learning path tailored to today's Dynamics 365 masterminds and designed to prepare you for industry-recognized Microsoft certifications.
Visit Microsoft Learn
2022 Release Wave 2Check out the latest updates and new features of Dynamics 365 released from October 2022 through March 2023
The FastTrack program is designed to help you accelerate your Dynamics 365 deployment with confidence.
FastTrack Community | FastTrack Program | Finance and Operations TechTalks | Customer Engagement TechTalks | Upcoming TechTalks | All TechTalks
Till Nav 2009 if time driven actions were needed, it was done using automation NTimer.dll (NavTimer). With Nav 2013 and newer Versions Microsoft recommends to avoid usage of automations. As a result many of the common used automations, shipped with Nav 2009 and earlier, disappeared. There are few descriptions, how to solve common issues formerly solved with automations. So, let’s have a look at the Timer issue.
The .Net Framework contains class System.Timers.Timer in assembly System.dll. To use and test it, create a new codeunit and add some global variables:
Variable Timer is of subtype System.Timers.Timer. We set properties RunOnClient to false, but WithEvents to true. Only one of these properties can be set to true at one time, both together is not allowed. But ok, we need the Triggers (in .Net called Events). With RunOnClient=false, the code runs on the server … and that’s ok. Setting WithEvents to true we get automatically all embedded .Net Events written in the C/AL code, in that case Timer::Elapsed(sender : Variant;e : DotNet “System.Timers.ElapsedEventArgs”) and Timer::Disposed(sender : Variant;e : DotNet “System.EventArgs”). We only use the first one.
In the sample we want create a file and write lines into the file, step by step, every 3 seconds one line. We use a Counter for a break condition.
Counter := 0; // Counter is an Integer variable
IF EXISTS('c:\temp\sample.txt') THEN
ERASE('c:\temp\sample.txt'); // delete the file, if it already exists
TextFile.CREATE('c:\temp\sample.txt'); // TextFile is a FILE variable
TextFile.TEXTMODE := TRUE;
Timer := Timer.Timer(); // create a Timer instance
Timer.Interval := 3000; // i.e. 3 secs (unit is ms)
Timer.Enabled := TRUE;
Timer.Start(); // starts the timer
Timer::Elapsed(sender : Variant;e : DotNet "System.Timers.ElapsedEventArgs")
Counter := Counter + 1;
TextFile.WRITE('line ' + FORMAT(Counter) + ', ' + FORMAT(TODAY) + ' ' + FORMAT(TIME));
// stop timer after trigger Elapsed was called 10 times
IF Counter > 10 THEN BEGIN
Timer.Enabled := FALSE;
Timer.Stop(); // stops the timer
Business Applications communities