I have an application hosting powershell, everything is running in a background worker and until now everything was ok 🙂
Runspace space = RunspaceFactory.CreateRunspace(this); // this -> a class derived from PSHost space.ApartmentState = System.Threading.ApartmentState.STA; space.ThreadOptions = PSThreadOptions.UseCurrentThread; space.Open();
Now I wanted to add a possibility to import modules. So I decided to use InitialSessionState. I changed my code to this:
InitialSessionState iss = InitialSessionState.CreateDefault(); iss.ImportPSModule(...); Runspace space = RunspaceFactory.CreateRunspace(this, iss); space.ApartmentState = System.Threading.ApartmentState.STA; space.ThreadOptions = PSThreadOptions.UseCurrentThread; space.Open();
So, basically I used an other overload of CreateRunspace using the InitialSessionState too.
I try to translate from german to english:
grateful for any help
Unfortunately, we don't have a big audience here who's working with PowerShell in this way. Apologies that you haven't been able to get an answer; I'm hoping you'll consider trying on someplace like StackOverflow, which tends to get a bigger Dev audience, or in the #powershell channel on IRC, which also has a much bigger Dev audience.
You must be logged in to reply to this topic.