private void backgroundWorker2_DoWork() { lock (this) { IPAddress ipAddress = clientSettings.GetIPAddress(); serverMsBuildUpdaterListener = new TcpListener(ipAddress, agentSettings.Port); // Gives a Signal to the initial thread that the agent client Listener is initialized Monitor.Pulse(this); } UpdateProgress uiUpdater1 = new UpdateProgress(DisplayClientMessage); serverMsBuildUpdaterListener.Start(); clientMsBuildTcpAgentListner = default(TcpClient); clientMsBuildTcpAgentListner = serverMsBuildUpdaterListener.AcceptTcpClient(); // Will update the status of the agents execution (MS Build Log) until the client is connected with the agent. UpdateProgress uiUpdater = new UpdateProgress(DisplayMsBuildLogMessage); while (isConnected) { NetworkStream serverStream = clientMsBuildTcpAgentListner.GetStream(); byte[] inStream = new byte[10025]; serverStream.Read(inStream, 0, (int)clientMsBuildTcpAgentListner.ReceiveBufferSize); string returndata = System.Text.Encoding.ASCII.GetString(inStream); if (returndata != String.Empty) { this.Dispatcher.BeginInvoke(uiUpdater, returndata); //this.Invoke(uiUpdater, returndata); } } }
private static void InitializeSettings() { clientSettings = new IpAddressSettings(ConfigurationManager.AppSettings["clientIp"], ConfigurationManager.AppSettings["clientPort"]); agentSettings = new IpAddressSettings(ConfigurationManager.AppSettings["agentIp"], ConfigurationManager.AppSettings["agentPort"]); msBuildLogSettings = new IpAddressSettings(ConfigurationManager.AppSettings["agentIp"], ConfigurationManager.AppSettings["msBuildAgentPort"]); Console.BackgroundColor = ConsoleColor.DarkGreen; commandsToBeExecuted = new ConcurrentQueue <string>(); messagesToBeSend = new ConcurrentQueue <MessageArgsLogger>(); cts = new CancellationTokenSource(); token = cts.Token; currentlyExecutedProc = null; lockObject = new Object(); agentListener = new TcpListener(agentSettings.GetIPAddress(), clientSettings.Port); agentListener.Start(); BaseLogger.Log.Info(AgentSettingsInitializedMsg); Console.WriteLine(AgentSettingsInitializedMsg); }