Axapta Threads for normal method

I would like to know if possible how to execute a method by thread even if this method is not coded with thread execution code.

See this Example bellow…

static void JobutilElements(Args _args)

{

utilElements utilElements;

;

while select utilElements

where utilElements.recordType == UtilElementType::Table && utilElements.name like ‘pba*’

{

//table2Excel( utilElements.name ,’’,true); the one wanted excecute by thread.

//forceByThread(str methodName,container parameterWrapped);

forceByThread(table2Excel, ContainerParams);

}

}

First of all, you shouldn’t go crazy about threads - threads are relatively expensive and creating too many threads may greatly reduce performance. It’s always important to think about the overhead and address it as appropriate (e.g. by pooling).

You can use Thread class in AX (see an example here), but it’s not actually recommended in typical cases. The alternative is batch processing (greatly improved in AX2012) - it allows you to use a simple asynchronous processing and also parallelism inside batches (see Batch Parallelism).

In some cases, you may consider writing difficult parts in .NET (using TPL, for instance), if you can reasonable plug it into the whole solution (which is typically quite difficult :frowning: ).

Please always add a tag for your version of AX; capabilities of AX3 and 2012 are very different.

When you said “but it’s not actually recommended in typical cases.” This means it’s feasible. Let’s also say that in my case performance is not an issue and the goal is to have an elegant solution easy to read.

Because right now if I want to execute a method by thread, I have to create another method with the parameter (thread t). I just want to know if I could save myself some annoying work. I would like to write the method once and have a way to call it sequence or by thread, without batch processing.

Thanks again for you great help

Would it be right to say:

If I build a method with the only parameter a container, I would be able to code a shell method like that:

static container Call(str methodName, boolean asynchronExecution, container paramContainer){ /* the code */}

I think this is what i’m looking for as a temporary solution.