public void StartWork() { var request = _requestPool.TakeAvailableRequest(); if (request.State == RequestState.None) { return; } IncrementActiveWorkersCount(); var client = new CustomTcpClient(request.Id); client.BytesReceived += Client_BytesReceived; client.ErrorReceived += Client_ErrorReceived; client.ResponseReceived += Client_ResponseReceived; client.StartClient(); }
private void connectToClient() { object criticalSection = new object(); lock (criticalSection) { Task.Run(() => { try { string ipAddress = textboxClientIP.Text; int port = int.Parse(textboxClientPort.Text); _customTcpClient = new CustomTcpClient(ipAddress, port, this, this); _customTcpClient.Connect(); clientConnected(); } catch (Exception ex) { Log(ex.Message); } }); } }