开发者

Having trouble running this C# code on XP

开发者 https://www.devze.com 2023-01-14 08:03 出处:网络
I\'m writing an application that can run PowerShell scripts which I\'d like to be run on the application\'s thread. The following code:

I'm writing an application that can run PowerShell scripts which I'd like to be run on the application's thread. The following code:

Runspace runspace = RunspaceFactory.CreateRunspace();  // create Powershell runspace
runspace.ThreadOptions = PSThreadOptions.UseCurrentThread;

Works and compiles fine on Windows 7, but can't be compiled in XP due to these errors:

 'System.Management.Automation.Runspaces.Runspace' does not contain a definition for 
    'ThreadOptions' and no e开发者_如何学运维xtension method 'ThreadOptions' accepting a first argument of type
    'System.Management.Automation.Runspaces.Runspace' could be found (are you missing a using 
    directive or an assembly reference?)


    The name 'PSThreadOptions' does not exist in the current context

Is this issue related to powershell v1 vs v2? I have the .NET 4 install on the XP machines (and VS 2010). Thanks!


From here:

"This property is introduced in Windows PowerShell 2.0."

0

精彩评论

暂无评论...
验证码 换一张
取 消