I am writing an application where I spawn a persistent remote runspace.
Then for every request I create an object of System.Management.Automation.Powershell class, associate it with the runspace, add a powershell script and invoke the same. Once the script is invoked, I dispose the System.Management.Automation.Powershell class object. Here, I do not dispose, the runspace (powershell session).
After running my application for some time (>2-3 hours) the powershell call fails with an exception that says the quota for Maximum concurrent commands per shell has exceeded.
Since, I create a new instance of System.Management.Automation.Powershell class for every request, I was wondering how/why will the same script fail after 2-3 hours with the mentioned exception.
I wanted to understand, if there is something, I need to additionally dispose/cleanup?
I see MaxConcurrentCommandsPerShell is set to a reasonably high value of 1024, wanted to know how this limit is evaluated. I am executing a script in the shell and, do not think script commands will be executed concurrently, it would be rather sequential.
Can you please help if my understanding is incorrect somewhere?
Warm Regards
Himanshu Agarwal