Thread return value to caller form

I want to know if its possible to execute a thread and when the thread finish is execution, to return the value the the caller form.

In HTML, AJAX does the trick but not sure if its possible in Axapta

Thanks

If your question is about the Thread class in X++, wait until the thread finishes and then call its getOutputParm() method. Or you can always use a shared repository (e.g. database).

I see you’re struggling with threads in AX for some time, but they are not as robust as in .NET, for example, and they are actually used rarely in AX (the recommended mean of parallel computation is batch processing). Maybe you’re trying to apply patterns from languages that work differently than your current language. If you described what you’re trying to implement, maybe we could suggest alternative architecture that work better in AX.

If you want to do a serious multi-threading development, you should rather write a .NET component and utilize the Task Parallel Library.

If your question is about the Thread class in X++, wait until the thread finishes and then call its getOutputParm()

When you say wait until the thread finishes… the only thing telling me its finished , is if I put → print ‘Finish’ but I want another way to know the thread is finish. info method dont popup and using timer makes my forms blink.

Maybe if I could replicate the way print works and use it for something else…

Thanks for your moral support :slight_smile:

It’s not a rocket science and you could find examples on internet…

thread = new Thread();
thread.run(classNum(TestThread), staticMethodStr(TestThread, runInThread));

while (thread.status() != 2)
{
   sleep(500);
}
[result] = thread.getOutputParm();

But its rocket science to not lock your session while waiting.

Your way you lock session just like normal execution.

Sorry if I’m rude.

But that’s exactly what you have to do if you want to get a return value. If you want a continuation, you’ll have to execute it by yourself from inside your task; X++ doesn’t have any support for such things.

You can simply change state of shared resource from your thread and let the form to periodically check the state (with setTimeOut()). Or maybe you could implement the Observer pattern.

It’s up to you.

There are so many possible things to do, but only you know your requirements and limitations.