Could someone explain the Runspace PSThreadOptions?

Viewed 142

My main question is does 1 RunSpace represent 1 thread.

I read this post: Process vs Instance vs Runspace in PowerShell

And originally I understood it as:

You have a currently running powershell process.

A runspace object is created within powershell's process address space.

It sets up and manages it's own thread within the main process.

You would create an object that represent the script you want to run in that thread with [powershell]::create()

Then pass it to the runspace to be executed within the thread it manages.

However after looking at the PSThreadOptions

https://docs.microsoft.com/en-us/dotnet/api/system.management.automation.runspaces.psthreadoptions?view=pscore-6.2.0

I'm a little confused - if (as I originally thought) 1 runspace = 1 thread why does it have an option to create a new thread for each invocation (I'm asuming they mean for each time you call .invoke() on an already created object and not just if you reinstanciate it) and also in what instance might someone use the current thread?

Any clarification on how these options work any corrections you can offer to my current understanding of things would be very much appreciated

Many Thanks

Nick

0 Answers
Related