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; } }