/// <summary> /// Note: Calls are serialized by _serverProcessLauncher, so no need to lock /// </summary> private void AfterProxyCreated(CreateProcessResult serverProcess) { Logger.LogInfo("AfterProxyCreated (pid={0}", serverProcess.Process.Id); #if PROFILE_SERVER var timeout = TimeSpan.FromSeconds(120.0); System.Diagnostics.Trace.WriteLine(string.Format("You have {0:n0} seconds to start the server process with a port argument of {1}.", timeout.TotalSeconds, ((IPEndPoint)_tcpListener.LocalEndpoint).Port)); #else var timeout = TimeSpan.FromSeconds(5.0); #endif Logger.LogInfo("AfterProxyCreated: Wait for TCP client connection from server process."); if (!_waitForConnection.WaitOne(timeout)) { throw new InvalidOperationException( string.Format("Child process did not connect to server within {0:n0} seconds.", timeout.TotalSeconds)); } _ipcStream = new IpcStreamOverNetworkStream(_serializer, _tcpClient.GetStream()); // Ensure process is alive and ready to process requests Logger.LogInfo("AfterProxyCreated: Wait for \"Hello\" message from server process."); WaitForProcessHelloMessage(); // Start reading process output Logger.LogInfo("AfterProxyCreated: Start receive response thread."); _receiveResponsesThread.ResponseReceived += response => { var callback = _callbacks.Remove(response.RequestId); callback(response); }; _receiveResponsesThread.EventReceived += @event => { OnEventReceived(@event); }; _receiveResponsesThread.Start(_ipcStream); Logger.LogInfo("AfterProxyCreated: Start send request thread.."); _sendRequestsThread.RequestError += OnRequestError; _sendRequestsThread.Start(_ipcStream, _requestQueue); }
private void AfterProxyCreated(CreateProcessResult processResult) { Invariants.Assert(processResult != null); Logger.LogInfo("AfterProxyCreated (pid={0}", processResult.Process.Id); #if PROFILE_SERVER var timeout = TimeSpan.FromSeconds(120.0); System.Diagnostics.Trace.WriteLine(string.Format( "You have {0:n0} seconds to start the server process with a port argument of {1}.", timeout.TotalSeconds, ((IPEndPoint)_tcpListener.LocalEndpoint).Port)); #else var timeout = TimeSpan.FromSeconds(30.0); #endif Logger.LogInfo("AfterProxyCreated: Wait for TCP client connection from server process."); var serverStartedSuccessfully = _waitForConnection.WaitOne(timeout) && _tcpClient != null; Invariants.CheckOperation(serverStartedSuccessfully, $"Child process did not connect to server within {timeout.TotalSeconds:n0} seconds."); _ipcStream = new IpcStreamOverNetworkStream(_serializer, _tcpClient.GetStream()); // Ensure process is alive and ready to process requests Logger.LogInfo("AfterProxyCreated: Wait for \"Hello\" message from server process."); WaitForProcessHelloMessage(); // Start reading process output Logger.LogInfo("AfterProxyCreated: Start receive response thread."); _receiveResponsesThread.ResponseReceived += response => { var callback = _callbacks.Remove(response.RequestId); callback(response); }; _receiveResponsesThread.EventReceived += @event => { OnEventReceived(@event); }; _receiveResponsesThread.FatalError += (sender, args) => { HandleReceiveThreadFatalError(args); }; _receiveResponsesThread.Start(_ipcStream); Logger.LogInfo("AfterProxyCreated: Start send request thread.."); _sendRequestsThread.SendRequestError += HandleSendRequestError; _sendRequestsThread.Start(_ipcStream, _requestQueue); // Server is fully started, notify consumers _isServerRunning = true; OnProcessStarted(); }