RamblingCookieMonster / Invoke-Parallel

Speed up PowerShell with simplified multithreading
MIT License
384 stars 88 forks source link

Using a shared & synchronized variable to hold a counter #58

Open banyula opened 6 years ago

banyula commented 6 years ago

I need to display the number of records being processed by Invoke-Parallel in a WinForms variable. For that I need to keep a Counter variable. I tried Boe's synchronized hash table however it did not work, numbers were erratic and counter was wrong. I am able although to display an online array list of the records being processed, however the count is needed for displaying a progress bar using WinForms.

I assume this is an old request, so I wonder if you can throw a sample script to show how to achieve it.

sheldonhull commented 5 years ago

Fyi I've had success with this using PSframework. There are runspaxe functions to allow working with an object in a thread safe manner. Putting note here in case it helps someone else who sees this.

banyula commented 5 years ago

Fyi I've had success with this using PSframework. There are runspaxe functions to allow working with an object in a thread safe manner. Putting note here in case it helps someone else who sees this.

Could you please provide a sample code using PSframework to serialize an object in a thread. I was checking its functionality and was quite confusing to me.