but I am still confused about the whole point of using the mutex - without using it in the window procedure, isn't there a possibility my UI thread will try to access the progress value when the worker thread is updating it? yes, but in this particular program (operation thread writes and main thread only reads), that wouldn't matter - so the main thread may update the progress bar 1 millisecond late it is no big deal in this case.
I think a mutex to synchronize the changing of the progress bar value is over-kill (somebody may come along and disagree) My feelings are (I 'm going to try these out): If the main thread must not be allowed to continue until the operation is completed - then the you might as well put the operation in the main thread.
In the third line, which is the Process script block of the For Each-Object cmdlet, the cmdlet searches the message property of each incoming object for "bios".
If the string is found, the message is added to $out.
So the threading possibility is not used to it's fullest potential.
So really, it could all have been done in the main thread.
This command displays the progress of a For loop that counts from 1 to 100.
The Write-Progress command includes a status bar heading ("activity"), a status line, and the variable $I (the counter in the For loop), which indicates the relative completeness of the task.
The ‘2.c’ example below shows a simpler way of accessing such shared variable – a TGp4Aligned Int record.Your version works exactly as I intended - I had suspected maybe I only one thread was necessary...I now understand why the main thread was being blocked out (one of those things that now seems completely obvious to me)...I’ve also put together a demo project which demonstrates all techniques.First idea is to send a windows message with a ‘percent of processed items’ as a parameter to the main form and let it update itself.It is updated from the worker thread and is read from a timer on a form.