public void ThreadWrite() { try { //TODO remove flush mode in production _loggerWrite = new CLogger(GetTimeConnIpPort() + "_Writer", true, _logSubdir, true); while (true) // foreach (byte[] message in _queueWriteBinary.GetConsumingEnumerable()) { byte[] message = _queueWriteBinary.GetElementBlocking(); //2018-05-20 process exit if queue is empty if (message == null) { _loggerWrite.Log("Exit with empty queue"); OnDisconnect(); IsThreadWriteFinished = true; return; } //was 3 changed to 10 2017-10-25 _queueWriteBinary.CheckLimit(10, true, 3, _tcpConnectionUser, "TCPConnection._queueWriteBinary"); if (!IsConnected) { OnDisconnect(); _loggerWrite.Log("Exit on non empty queue"); break; } try { sw1_1.Reset(); sw1_1.Start(); WriteMessage(message); sw1_1.Stop(); _loggerWrite.Log("Write sw1_1.Milliseconds=" + sw1_1.ElapsedMilliseconds + " sw1_1.Ticks=" + sw1_1.ElapsedTicks); } catch (Exception e) { if (!IsConnected) { OnDisconnect(); break; } } } IsThreadWriteFinished = true; } catch (Exception e) { Error("ThreadWrite", e); } }
private void ThreadFunc() { while (true) { try { CTradingData tc = _bqTraderData.GetElementBlocking(); sw1.Reset(); sw1.Start(); sw2.Reset(); sw2.Start(); sw3.Reset(); sw3.Start(); bool isReady = _client.IsStockOnline && _client.IsDealsOnline; //2018-02-20 change to 1 _bqTraderData.CheckLimit(10, isReady, 1, (IAlarmable)_client, "CTradersDispatcher"); sw2.Stop(); if (enmTradingEvent.AuthResponse == tc.Event) { SendUpdateAuthResponse(tc.ConnId, (CAuthResponse)tc.Data); } else if (enmTradingEvent.UserUpdatePositionMonitor == tc.Event) { SendUpdateUserPosMonitor(tc.ConnId, (CUserPosMonitorUpdate)tc.Data); } else if (enmTradingEvent.UserOrdersUpdate == tc.Event) { SendUpdateUserOrders(tc.ConnId, (CUserOrdersUpdate)tc.Data); } else if (enmTradingEvent.UserUpdatePosLog == tc.Event) { SendUpdateUserPosLog(tc.ConnId, (CUserPosLogUpdate)tc.Data); } else if (enmTradingEvent.UpdateUserPosLogLate == tc.Event) { SendUpdateUserPosLogLate(tc.ConnId, (CUserPosLogUpdLate)tc.Data); } else if (enmTradingEvent.UserUpdateDealsLog == tc.Event) { SendUpdateUserDealsLog(tc.ConnId, (CUserDealsLogUpdate)tc.Data); } else if (enmTradingEvent.UserUpdateVM == tc.Event) { SendUpdateTotalVM(tc.ConnId, (CUserVMUpdate)tc.Data); } else if (enmTradingEvent.UserUpdateAvailableTickers == tc.Event) { SendUpadateAvailableTickers(tc.ConnId, (CAvailableTickers)tc.Data); } else if (enmTradingEvent.UpdateMoneyData == tc.Event) { SendUpadateAccountMoney(tc.ConnId, (CUserMoney)tc.Data); } else if (enmTradingEvent.StopLossTakeProfitAccepted == tc.Event) { SetStopLossTakeProfitAccepted(tc.ConnId, (CSetOrder)tc.Data); } else if (enmTradingEvent.UpdateInstrumentParams == tc.Event) { SendUpdateInstrumentsParams(tc.ConnId, (CUpdateInstrumentParams)tc.Data); } sw1.Stop(); //2017-11-02 removed /* if (sw1.ElapsedMilliseconds > 10) * { * System.Threading.Thread.Sleep(1); * } */ } catch (Exception e) { Error("CTradersDispatcher.ThreadFunc", e); } } }