private string HandleReceiving() { string message = ""; try { StreamReader streamReader = new StreamReader(this.client.GetStream(), Encoding.Unicode); string streamData = ""; bool insertionSuccess; DateTime timeoutFrom; TimeSpan span; int timeoutSeconds; while (this.IsWorking) { streamData = streamReader.ReadLine(); if (!String.IsNullOrWhiteSpace(streamData)) { insertionSuccess = false; timeoutFrom = DateTime.Now; do { span = DateTime.Now - timeoutFrom; timeoutSeconds = (int)span.Seconds; if (timeoutSeconds > ReceivingInsertionTimeout) { throw new Exception($"timeout - command container not released / {message}"); } insertionSuccess = receivedCmdContainer.InsertCommand(streamData); }while (!insertionSuccess && this.IsWorking); } } message = "ClientHandler receiving process ended"; } catch (Exception exception) { string disMsg = Disable(); message = $"ClientHandler receiving process exception: {exception.Message}"; if (!String.IsNullOrEmpty(disMsg)) { message += $" | {disMsg}"; } } return(message); }
private void HandleReceiving() { try { string cmd = this.sReader.ReadLine(); string errorMsg = ""; DateTime timeoutFrom = DateTime.Now; int loopCounter = 0; TimeSpan span; int timeoutSeconds; while (!receivedCmdContainer.CheckIfEmpty()) { loopCounter++; if (loopCounter % 100 != 0) { continue; } //makes CheckIfEmpty() calling faster span = DateTime.Now - timeoutFrom; timeoutSeconds = (int)span.Seconds; if (timeoutSeconds > ReceivingInsertionTimeout) { throw new Exception("timeout - command container not released"); } } if (!receivedCmdContainer.InsertCommand(cmd)) { throw new Exception("cannot insert command to received command container"); } } catch (Exception exception) { this.receivingInfoPacket.Obj = false; this.receivingInfoPacket.Msg = exception.Message; } }