In this post, we will see how to resolve ThreadJob in powershell is not working with global variables
Question:I have the below code where
myValueswill be updated by multiple functions (in this file) and I want to capture that change and process
myValuesin a different thread so that the current execution of updating
myValuesis not stopped. But
logsToDashboardis not event getting called in here. Not sure what am i missing. Would appreciate any leads.
Best Answer:You need to use the
using:scope modifier to reference a local a variable in your new thread. Also using
global:is pointless in your code.
-ArgumentListand, you can but not mandatory, add a
paramblock to your function. Without the
paramblock you would refer to the list using
If you have better answer, please add a comment about this, thank you!