Skip to content

Exception calling "BeginInvoke" with "0" argument(s): "Cannot perform the operation because the runspace pool is not in the 'Opened' state. The current state is 'Closed'." #111

@codykonior

Description

@codykonior

I'm coming across this issue frequently during development. I have a module I'm working on and often need to Import-Module Blah-Force to bring in the latest changes and test it (like in ISE). This module has a RequiredModules of PoshRSJob and functions which use Start-RSJob and others.

If I run steps manually one by one like so, it works:

Import-Module Blah -Force
...
Start-Command
... Start-RSJob

I realised this is because there is a small delay when you run them like that. If I run them all at once with a delay it works:

Import-Module Blah -Force
Start-Sleep -Seconds 1
Start-Command
... Start-RSJob

But if they execute immediately after each other with no delay I get the above error. Every time!

Import-Module Blah -Force
Start-Command
... Start-RSJob

Any ideas why this is happening?

Metadata

Metadata

Assignees

Labels

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions