/// <summary> /// Set the new runspace state. /// </summary> /// <param name="state">the new state</param> /// <param name="reason">An exception indicating the state change is the /// result of an error, otherwise; null. /// </param> /// <remarks> /// Sets the internal runspace state information member variable. It also /// adds RunspaceStateInfo to a queue. /// RaiseRunspaceStateEvents raises event for each item in this queue. /// </remarks> protected void SetRunspaceState(RunspaceState state, Exception reason) { lock (SyncRoot) { if (state != RunspaceState) { _runspaceStateInfo = new RunspaceStateInfo(state, reason); //Add _runspaceStateInfo to _runspaceEventQueue. //RaiseRunspaceStateEvents will raise event for each item //in this queue. //Note:We are doing clone here instead of passing the member //_runspaceStateInfo because we donot want outside //to change our runspace state. RunspaceAvailability previousAvailability = _runspaceAvailability; this.UpdateRunspaceAvailability(_runspaceStateInfo.State, false); _runspaceEventQueue.Enqueue( new RunspaceEventQueueItem( _runspaceStateInfo.Clone(), previousAvailability, _runspaceAvailability)); } } }
/// <summary> /// Set the new runspace state. /// </summary> /// <param name="state">the new state</param> /// <param name="reason">An exception indicating the state change is the /// result of an error, otherwise; null. /// </param> /// <returns>Previous runspace state</returns> /// <remarks> /// Sets the internal runspace state information member variable. It also /// adds RunspaceStateInfo to a queue. /// RaiseRunspaceStateEvents raises event for each item in this queue. /// </remarks> private RunspaceState SetRunspaceState(RunspaceState state, Exception reason) { RunspaceState prevState; lock (_syncRoot) { prevState = _runspaceStateInfo.State; if (state != prevState) { _runspaceStateInfo = new RunspaceStateInfo(state, reason); //Add _runspaceStateInfo to _runspaceEventQueue. //RaiseRunspaceStateEvents will raise event for each item //in this queue. //Note:We are doing clone here instead of passing the member //_runspaceStateInfo because we donot want outside //to change our runspace state. RunspaceAvailability previousAvailability = _runspaceAvailability; this.UpdateRunspaceAvailability(_runspaceStateInfo.State, false); _runspaceEventQueue.Enqueue( new RunspaceEventQueueItem( _runspaceStateInfo.Clone(), previousAvailability, _runspaceAvailability)); PSEtwLog.LogOperationalVerbose(PSEventId.RunspaceStateChange, PSOpcode.Open, PSTask.CreateRunspace, PSKeyword.UseAlwaysOperational, state.ToString()); } } return prevState; }