Notifications
Clear all

[Closed] Wait for backgroundworker

Hey all,

I’m using .net to implement some background workers (multithreading) in my script.

The pseudocode is as follows:

>create array
>start a bunch of background workers to fill array with values
>wait until background workers are finished ***
>manipulate array

The problem is the line marked with “***”. How can I prevent maxscript from continuing, until the background workers are finished? I tried setting up a “do while not [backgroundworker].isbusy” but that just freezes max since the isbusy value isn’t updated until the loop completes.

I found a workaround, which is placing:


 (dotnetclass "System.Windows.Forms.Application").DoEvents()
 

within the loop. This “works”, the only problem is that it re-activates everything in the max UI (including my rollout UI) even while the loop is evaluating. I need a solution that prevents the user from being able to change the UI until the workers are complete (and simply disabling the rollout controls is not an option in this case)

Any ideas?

tl;dr: I need a function that waits for background workers to complete, without allowing UI interaction while they’re working, and without entering into an infinite loop while checking to see if they’re busy.

1 Reply

Nevermind, figured out how to do it using an autoResetEvent, and its waitone() and set() methods.