forked from NTTLimitedRD/PowerShell.REST.API
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathRunspacePoolWrapper.cs
48 lines (44 loc) · 943 Bytes
/
RunspacePoolWrapper.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
namespace DynamicPowerShellApi
{
using System;
using System.Management.Automation.Runspaces;
/// <summary>
/// The run space pool wrapper.
/// </summary>
public class RunspacePoolWrapper : IDisposable
{
/// <summary>
/// The run space pool.
/// </summary>
private static readonly Lazy<RunspacePool> LazyRunspacePool = new Lazy<RunspacePool>(
() =>
{
var rs = RunspaceFactory.CreateRunspacePool(1, 2);
rs.Open();
return rs;
});
/// <summary>
/// Prevents a default instance of the <see cref="RunspacePoolWrapper"/> class from being created.
/// </summary>
private RunspacePoolWrapper()
{
}
/// <summary>
/// Gets the run space pool.
/// </summary>
public static RunspacePool Pool
{
get
{
return LazyRunspacePool.Value;
}
}
/// <summary>
/// Dispose of the run space.
/// </summary>
public void Dispose()
{
LazyRunspacePool.Value.Close();
}
}
}