I’m playing around with .Net MXS Multi Threading and search a solution for: How to execute a function (multi threaded) with a parameter. Google didn’t help me so far.
Here’s the code which has two problems:
[ol]
[li]The code drops an error after executing the multi thread function (this can be prevented by try/catch)[/li][li]3Ds Max stalls, during execution! This is then of course useless since this shall not happen with multi threading[/li][/ol]
fn doSomeStuff myText =
(
for i = 1 to 1000000 do pi * pi * pi
print myText
print "thread done ..."
)
myThread = dotNetObject "system.componentModel.backgroundWorker"
dotnet.addEventHandler myThread "DoWork" (doSomeStuff "test")
myThread.runWorkerAsync()
– Runtime error: dotNet event handler must be a functions, got: “test”
If you delete the function parameter and the parenthesis, the code works perfectly - no 3Ds Max stalling and no error. But i need to hand over a function parameter! Is this just not possible?
This is black magic! But it works, thank you! But i got problems with the variables scope and since i don’t want to use global variables, i looked for another solution and found one. You can hand over an argument when starting the thread with “RunWorkersAsync” and here’s a great example how to use this with arrays: