I see that Jean-Paul Mikkers async poweshell example over at CodeProject.com is tearing down the pipeline and recreating it after every script execution. Does anybody know if there is a particular reason why it’s done this way, or does the pipeline need to be recreated every time.
I’ve tried execution on it multiple times with my own example, but there could be knock on effects which I don’t see with only a few 100-1000’s of executions.
I have (unit test) code which creates a single Runspace to create multiple pipelines, none of which are disposed,1 in turn.
This all runs without problem.
Of course, if a pipeline changes the state of the Runspace (e.g. adds a variable, changes directory, loads a snapin, …) then this could impact the result of pipelines.
Summary: “Is it neccessary?”: No. But you might find it gives better/worse performance (and the answer to this will vary with PSH version). Unless you find creating the pipeline causes a performance impact, follow what provides the simplest design for your application.
1 One for the to do list 🙂