/// <summary> /// Starts up the node and processes messages until the node is requested to shut down. /// </summary> /// <param name="enableReuse">Whether this node is eligible for reuse later.</param> /// <param name="shutdownException">The exception which caused shutdown, if any.</param> /// <returns>The reason for shutting down.</returns> public NodeEngineShutdownReason Run(bool enableReuse, out Exception shutdownException) { #if FEATURE_NAMED_PIPES_FULL_DUPLEX // Console.WriteLine("Run called at {0}", DateTime.Now); string pipeName = "MSBuild" + Process.GetCurrentProcess().Id; _nodeEndpoint = new NodeEndpointOutOfProc(pipeName, this, enableReuse); #else _nodeEndpoint = new NodeEndpointOutOfProc(_clientToServerPipeHandle, _serverToClientPipeHandle, this, enableReuse); #endif _nodeEndpoint.OnLinkStatusChanged += new LinkStatusChangedDelegate(OnLinkStatusChanged); _nodeEndpoint.Listen(this); WaitHandle[] waitHandles = new WaitHandle[] { _shutdownEvent, _packetReceivedEvent }; // Get the current directory before doing any work. We need this so we can restore the directory when the node shutsdown. while (true) { int index = WaitHandle.WaitAny(waitHandles); switch (index) { case 0: NodeEngineShutdownReason shutdownReason = HandleShutdown(out shutdownException); return(shutdownReason); case 1: INodePacket packet = null; int packetCount = _receivedPackets.Count; while (packetCount > 0) { lock (_receivedPackets) { if (_receivedPackets.Count > 0) { packet = _receivedPackets.Dequeue(); } else { break; } } if (packet != null) { HandlePacket(packet); } } break; } } // UNREACHABLE }
/// <summary> /// Starts up the node and processes messages until the node is requested to shut down. /// </summary> /// <param name="enableReuse">Whether this node is eligible for reuse later.</param> /// <param name="lowPriority">Whether this node should be running with low priority.</param> /// <param name="shutdownException">The exception which caused shutdown, if any.</param> /// <returns>The reason for shutting down.</returns> public NodeEngineShutdownReason Run(bool enableReuse, bool lowPriority, out Exception shutdownException) { // Console.WriteLine("Run called at {0}", DateTime.Now); string pipeName = NamedPipeUtil.GetPipeNameOrPath("MSBuild" + Process.GetCurrentProcess().Id); _nodeEndpoint = new NodeEndpointOutOfProc(pipeName, this, enableReuse, lowPriority); _nodeEndpoint.OnLinkStatusChanged += OnLinkStatusChanged; _nodeEndpoint.Listen(this); var waitHandles = new WaitHandle[] { _shutdownEvent, _packetReceivedEvent }; // Get the current directory before doing any work. We need this so we can restore the directory when the node shutsdown. while (true) { int index = WaitHandle.WaitAny(waitHandles); switch (index) { case 0: NodeEngineShutdownReason shutdownReason = HandleShutdown(out shutdownException); return(shutdownReason); case 1: while (_receivedPackets.TryDequeue(out INodePacket packet)) { if (packet != null) { HandlePacket(packet); } } break; } } // UNREACHABLE }