I am creating a runspace and sending powershell commands from an aspx web form, and all works well unless some bozo double clicks the submit button, in which case I get an error that the pipeline is already executing. (OK, it was me)
I use the following from http://www.leastprivilege.com/HostingPowerShellInASPNET.aspx
protected Collection runposh(string strCommand) { Runspace rs = GetRunspace(); Pipeline cmd = rs.CreatePipeline(strCommand); Collection results = cmd.Invoke(); return (results); } protected Runspace GetRunspace() { if (Cache["rs"] == null) { Runspace rs = RunspaceFactory.CreateRunspace(); rs.Open(); Cache["rs"] = rs; } return (Runspace)Cache["rs"] }
So, I thought I'd check the pipeline using: protected Collection runposh(string strCommand) { Runspace rs = GetRunspace(); try {
if (currentPipeline == null || currentPipeline.PipelineStateInfo.State != PipelineState.Running) { currentPipeline = rs.CreatePipeline(strCommand); Collection results = currentPipeline.Invoke(); return (results); } else { return (null); } } finally { } } Which works pretty good unless the bozo (still me) rapidly clicks the submit button over and over like a rabid squirrel on energy drinks. - Then it brings up a blank page, and you have to refresh, and pass the data again, which works.
I'd not worry about this, but some of these people that will be using the program make me look calm, so I am sure they will break it too ;)
|