Click to Rate and Give Feedback
MSDN
MSDN Library
Windows PowerShell Runspaces

A runspace provides a mechanism for hosting applications to execute pipelines programmatically in a well-constructed manner. Looked at in another way, a runspace created by a hosting application is an abstraction of the Windows PowerShell runtime that is used by the default hosting application Powershell.exe.

Runspaces construct a logical model of execution using pipelines that contain cmdlets, native commands, and language elements, which in turn ensures that the hosting application and its user do not need to know about the underlying execution of the cmdlets required to perform a task.

Communications

However, even though the runspace separates the hosting application from the pipeline execution, communications between the hosting application user and the underlying pipeline execution may occur in two ways. First, the execution may return results that may be displayed by the hosting application. Second, the elements of the pipeline may communicate directly with the host through one of two optional host interfaces that can be specified when the runspace is configured.

Creating a Runspace

Runspaces are created using the RunspaceFactory class provided by the System.Management.Automation.Runspaces namespace. This class provides a single, overloaded CreateRunspace method that returns a Runspace object, which in turn is used to create the Windows PowerShell host and Windows PowerShell pipeline.

Here is the code typically used to create and open a runspace.

C#
Runspace myRunSpace = RunspaceFactory.CreateRunspace(config);
myRunSpace.Open();

For an example of creating runspaces, see How to Create a Windows PowerShell Hosting Application in the Windows PowerShell Programmer's Guide.

For an example of implementing host interfaces, see Creating Applications that Use a Custom Host in the Windows PowerShell Programmer's Guide.

See Also

Footer image

Send comments about this topic to Microsoft.

Tags What's this?: Add a tag
Community Content   What is Community Content?
Add new content      
Processing
© 2008 Microsoft Corporation. All rights reserved. Terms of Use  |  Trademarks  |  Privacy Statement
Page view tracker