Simple Threading in AX 2012

In this post I want to show, how easily you can utilize the Thread class in AX 2012.

Simple Thread example

First we want to setup a new class.

Next we want to add two static methods, one “slow” method which will use a sleep to simulate a lengthy runtime¬†and one “fast” method.

The idea here is that we invoke the “slow” method at first and the “fast” method later on. Todo so, we setup a new job.

First we create two new Thread objects, then we call the run method of it and pass the class plus the static method we want to execute. Like said, first the slow, then the slow.

Before we run the job, set break points to the both info(), as they will not pop up when running the job, because they run in a new worker thread.

First thing we will notice,¬†is that we will hit the “fast” method first.

AX2012 Threading Fast Method

If you continue, you will hit the “slow” method about 15 seconds later.

AX2012 Threading Slow Method
As you can see, working with threads in AX 2012 is very easy. Instead of waitin till the “slow” method is finished, the “fast” method gets invoked immediately after the “slow” fires.

If you need further information, I found this article on the Dynamics Community very helpful. It provides a little bit more inside into threads (also give the linked post in that article a chance).

You may also like...

Leave a Reply

Your email address will not be published. Required fields are marked *