Пример #1
0
        public PowershellPool(int poolSize, InitialSessionState initialSessionState, CancellationToken cancellationToken)
        {
            _poolMembers= new List<PowerShellPoolMember>(poolSize);
            _initialSessionState = initialSessionState;
            _cancellationToken = cancellationToken;

            for (var i = 0; i < poolSize; i++)
            {
                var powerShellPoolMember = new PowerShellPoolMember(this, i+1, initialSessionState);
                _poolMembers.Add(powerShellPoolMember);
                _availablePoolMembers.Add(powerShellPoolMember);
            }
        }
Пример #2
0
        public PowershellPool(int poolSize, InitialSessionState initialSessionState, CancellationToken cancellationToken)
        {
            _poolMembers       = new List <PowerShellPoolMember>(poolSize);
            _processedCount    = 0;
            _cancellationToken = cancellationToken;

            for (var i = 0; i < poolSize; i++)
            {
                var powerShellPoolMember = new PowerShellPoolMember(this, i + 1);
                _poolMembers.Add(powerShellPoolMember);
                _availablePoolMembers.Add(powerShellPoolMember);
            }

            _runspacePool = RunspaceFactory.CreateRunspacePool(initialSessionState);
            _runspacePool.SetMaxRunspaces(poolSize);
        }
Пример #3
0
        public void ReportAvailable(PowerShellPoolMember poolmember)
        {
            Interlocked.Decrement(ref _busyCount);
            lock (_countLock)
            {
                _processedCount++;
                poolmember.PercentComplete = 0;
            }

            poolmember.PercentComplete = 0;
            while (!_availablePoolMembers.TryAdd(poolmember, 1000, _cancellationToken))
            {
                _cancellationToken.ThrowIfCancellationRequested();
                Debug.WriteLine("WaitForAvailablePowershell - TryAdd failed");
            }
        }
Пример #4
0
        public void ReportAvailable(PowerShellPoolMember poolmember)
        {
            Interlocked.Decrement(ref _busyCount);
            lock (_countLock)
            {
                _processedCount++;
                poolmember.PercentComplete = 0;
            }

            poolmember.PercentComplete = 0;
            while (!_availablePoolMembers.TryAdd(poolmember, 1000, _cancellationToken))
            {
                _cancellationToken.ThrowIfCancellationRequested();
                Debug.WriteLine("WaitForAvailablePowershell - TryAdd failed");
            }
        }
Пример #5
0
 public void ReportStopped(PowerShellPoolMember powerShellPoolMember)
 {
     Interlocked.Decrement(ref _busyCount);
 }
Пример #6
0
 public void ReportStopped(PowerShellPoolMember powerShellPoolMember)
 {
     Interlocked.Decrement(ref _busyCount);
 }
Пример #7
0
 private bool TryWaitForAvailablePowershell(int milliseconds, out PowerShellPoolMember poolMember)
 {
     if (!_availablePoolMembers.TryTake(out poolMember, milliseconds, _cancellationToken))
     {
         _cancellationToken.ThrowIfCancellationRequested();
         Debug.WriteLine("WaitForAvailablePowershell - TryTake failed");
         poolMember = null;
         return false;
     }
     return true;
 }