web
You’re offline. This is a read only version of the page.
close
Skip to main content

Notifications

Announcements

No record found.

Community site session details

Community site session details

Session Id :
Microsoft Dynamics AX (Archived)

Create and run thread on server tier

(0) ShareShare
ReportReport
Posted on by

Hi there

I'm trying to create and to run a separated thread inside a method running server side. However, there's no error at all, but the thread itself seems never called. If I try the same on client side, all is running fine. Can anybody assist me?

Here's what I've done:

static server void threadController()

{

   ExecutePermission executePermission = new ExecutePermission();

   str               result;

   Thread            thread;

   ;

   executePermission.assert();

   thread = new Thread();

   thread.run(classnum(WorkToDo), staticmethodstr(WorkToDo, threadEntry));

   while (! thread.endDate())

   {

       sleep(1000);

   }

   result = conpeek(thread.getOutputParm(), 1);

   info("Message from thread: " + result);

}

static server void threadEntry(Thread _t)

{

   ;

   // do something (not implemented yet)

   _t.setOutputParm(["All done"]);

}

When I switch all on client tier, the infolog in threadController will raise "All done", when I switch to server thread, the outParm has length of zero elements.

How to solve?

Thank you for your help.

*This post is locked for comments

I have the same question (0)
  • Dick Wenning Profile Picture
    8,705 Moderator on at

    what is the aim of the parm return?

    you could ask the status of the thread

    0 = Thread never ran

    1 = Thread is executing

    2 = Thread has finished executing

    perhaps first check status if is finished.

  • Community Member Profile Picture
    on at

    The status is 2 - but still not executing the code inside threadEntry().

    Any other Ideas?

  • Martin Dráb Profile Picture
    237,965 Most Valuable Professional on at

    The same code works for me regardless it's on client or server. How exactly do you switch it from client to server?

  • Community Member Profile Picture
    on at

    Hi Martin

    I run a job and the job calls WorkToDo::threadController();

    threadController() and threadEntry(..) are both on class WorkToDo.

    So you say, can read out the 'All done' from thread output?

  • Martin Dráb Profile Picture
    237,965 Most Valuable Professional on at

    threadController() is a server-bound method, so it runs on server regardless of where the calling code runs.

    Yes, I do see "Message from thread: All done".

  • Community Member Profile Picture
    on at

    Of course it's server bound, it shall run on server. Is your threadController() also server bound?

  • Verified answer
    Martin Dráb Profile Picture
    237,965 Most Valuable Professional on at

    Well, I thought that answers to your last two questions are already in the sentence "The same code works for me regardless it's on client or server". I was serious. It works and I tested it both on client or server.

    But what do YOU mean by "If I try the same on client side, all is running fine." if you now say that it's always on server? Please give us your full code.

  • Community Member Profile Picture
    on at

    Sorry, think we talk at cross purposes, I try to explain:

    When I remove the 'server' modifer from threadController(), then it works (cause then it's runnig on client).

    But, the goal is to run this on server.

    In the mean time I have now recompiled and restored ever concerned object and restarted the AOS. And my, my: It works also for me!

    I have no clue, why it does not work earlier since it was exact the same code, may be a cache problem. But I'm happy now that it works!

    Thank you very much

  • Community Member Profile Picture
    on at

    HI Luigi,

    I executed the same same code in batch using Runbase batch and SysOperation framework.

    It works well in interactive mode, while it is not running in batch.

    I get thread status 3 in batch. 
    Please let me know whether thread works in Batch or not?

    If it works, do i need to change the code ?

  • Martin Dráb Profile Picture
    237,965 Most Valuable Professional on at

    aXdk, please notice that this thread was about AX 2009, while you're clearly talking about some newer version, because AX 2009 didn't contain the SysOperation framework. Your question may be related to CIL, which didn't exist in AX 2009 either, therefore such a discussion doesn't belong here. I suggest you create a new thread (with the right version tag) and explain your problem there. Don't forget to mention why you're trying to use the Thread class at all, instead of creating batch tasks as usual.

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Responsible AI policies

As AI tools become more common, we’re introducing a Responsible AI Use…

Neeraj Kumar – Community Spotlight

We are honored to recognize Neeraj Kumar as our Community Spotlight honoree for…

Leaderboard > 🔒一 Microsoft Dynamics AX (Archived)

#1
Martin Dráb Profile Picture

Martin Dráb 4 Most Valuable Professional

#1
Priya_K Profile Picture

Priya_K 4

#3
MyDynamicsNAV Profile Picture

MyDynamicsNAV 2

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans