Thread Server side

Hi,

I’m facing some issues trying to run a thread of a class with the property RunOn:Server, change the property to RunOn:Client is not a solution because this class will be called server side from various batch.

The code is really simple:

ExecutePermission permission = **new** ExecutePermission();

Thread t;

**permission.assert();**

t = **new** Thread();

a = t.run( **classnum** (className), **staticMethodStr** (className,staticMethodName));

CodeAccessPermission::revertAssert();

setting the property RunOn:Called from and spawning the thread in client side is perfectly working.

Please help I’m going crazy.

Thanks

Why are you trying to do such a thing in the first place? You aren’t even using a thread pool.
Can’t you use SysOperation framework with one of asynchronous execution modes?

Hi,

do you know the solution for my issue?
I don’t want to be impolite but, every time I post a question you answer with another questione saying to do differently. I have just resolved my business problem in another way I just want to know why a simple thing like running a thread server side seems to be impossible.

Thanks

Well, what’s wrong in pointing out to issues in your design and suggesting (hopefully) better solutions, or at least more options to choose from? I thought you would appricate it - I’m sorry that you don’t. :frowning_face:
If you can achieve your goal with standard and supported ways how to id it in AX 2012 (such as using SysOperation framework), why would you do it in a way that Microsoft advice against? You would be making everything more complicated and risky for yourself. I thought the reason may be that you don’t know how these things are done in AX.
If you insist on using Thread class, please tell us what problem you have with it. Just saying that you’re facing some issues doesn’t allow you to address your particular problem.

I already resolved with an async sysop, my topic was about thread and I wanted to discuss about thread.
I appreciate that you want to suggest me other ways but i would have appreciate also if you had pointed out something useful about the main topic.

If you think that what I said is not explicable of the problem I’m facing I can add more details.

But I don’t know how to be more clear.

If the code is executed in a server side method the thread is not spawned, or if it is, it’s not executing the code in the thread-called static method.

Isn’t the class or method (that you’re trying to call from the thread) bound to the client tier?
Are you executing your code as X++ or CIL? Does it behave the same if you try the other option?

Hi,

what you mean with “bound to the client tier”?
Method doesn’t contain the keywords Server/Client in his definition and the runOn property is setted to “Called from”.
If from a job a call the method (that contain only the code that I write In the first post) then the thread is spawned and executed.
But if that same method is called from a class that have the property runOn set to Server (in my case Application class) then the thread maybe is spawned (I don’t have a way to check) but for sure the code is not executed.

Either way X++(server-side)/CIL doesn’t call the method.

Maybe I’m wrong but when I debug from client (so with ax debugger) and I see in the call stack the figure representing the server I suppose that in that moment the code is executed server-side. Do you agree?

Thank you

Yes, bound to client would mean that either the whole class must execute on client (RunOn = Clie nt) or the method uses the client keyword (without server).
How are you determining whether your code was executed or not? Do you depend on debugger or on something what the method does? If you’re using a debugger and you’re executing CIL, are you using Visual Studio attached to Ax32Serv.exe? With “Just my code” unchecked? I have no idea if X++ debugging is possible, because I always used other ways for asynchronous precessing and never had to resort to this.

I don’t know either if there is other methods for CIL debugging but yes I’m using Visual Studio Attaching to Ax32Serv.exe with just my code unchecked etc.

Let’s make this convention, the method that contain the call thread.run we will call It simply the “method” from now and the method that have to run in thread we will call it the threadMethod.

If I debug the method in x++ I can proceed step by step executing all the instruction and then the debugger will break at the first breakpoint in the threadMethod.

But if I debug the method in CIL so with Visual Studio I can execute all the method like in the x++ version but then the breakpoint in the threadMethod will never be intercepted.

In the threadMethod I do some update in some tables (the table don’t save data per area so there is not a problem of different DATAAREAID and there is only 1 partition) and also I write a file (remote path) and neither the updates nor the write in the file is executed.