Notifications
Clear all

[Closed] BackgroundWorker context?

I’ve run into a little problem:

A BackgroundWorker (BGW) is running and listening for incomming data on a socket. This data can be a string I want to execute(). Works fine for scripts that juggle a few vars or some basic math. It fails for a “select $*” for example, everything that reaches outside of the BGW fails.

I’ve solved it by letting the BGW set a global var with the script-string and using a dotnet timer event outside of the BGW that polls this global var a few times a second and executes/clears it. Works fine but it doesnt really feel zen to me Is there a less convoluted way of doing this?

4 Replies

Instead of using the string “DoWork” in the BGW event try using “runWorkerCompleted”. This seems to put the worker in a queue and stops a lot of errors that crop up using a dotNet thread. The downside is that it’s not exactly a background worker as it waits for other stuff to finish, but it won’t cause any viewport slowdown as it won’t run the supplied function until max is idle.

The runWorkerCompleted is meant to be fired after doWork completes, but you can supply a runWorkerCompleted with no doWork and it will still fire. (I’m not sure if it’s meant to but it does )

Hi Jona, I think you dont have an alternative, you need to use that global var, so that it is created in the 3dsmax thread and that’s why you can run the “select $*” in the backgroundworker thread after… but have you tried “max select all” instead?

Thx for the tips!

“Select all” doesn’t work either, only scripts that operates on stuff in the BGW works, even tried this:

-dynamically create a macro containing the script and call that (desperate, I know )
-pass the script to a function created in the ‘root’, fails
-execute via a temp file etc… same

So every direct or indirect call from a BGW fails when executing it requires a crossing of the BGW boundry, Logical but hard to solve.

The only thing that did it was via the global var and a misused timer event, it is used as sort of a non-blocking while-do loop

Yeah… I know the feeling xD I’ve also tried many different ways to work around that