private void MonitorClient() { long lastRun = DateTime.Now.Ticks; while (_bKeepRunning) { try { TimeSpan ts = new TimeSpan(DateTime.Now.Ticks - lastRun); if (ts.TotalMilliseconds > 30000) { lastRun = DateTime.Now.Ticks; string sonda = GerarSonda(); List <int> toDelete = new List <int>(); foreach (ClientHandlerState state in dctClientes.Values) { logger.Info("Enviando sonda para cliente " + state.ClientNumber + "[" + state.ClientSocket.RemoteEndPoint.ToString() + "]"); try { SocketPackage.SendData(sonda, state.ClientSocket); } catch (Exception ex) { logger.Error("Erro ao enviar sonda para [" + state.ClientNumber + "] removendo cliente"); toDelete.Add(state.ClientNumber); } } if (toDelete.Count > 0) { foreach (int clientNumber in toDelete) { dctClientes.Remove(clientNumber); } } } } catch (Exception ex) { logger.Error("MonitorClient(): " + ex.Message, ex); } Thread.Sleep(100); } }
protected void queueProcessor() { logger.Info("Iniciando processamento da fila de envio streamer de Livro de Negocios"); long lastLogTicks = 0; while (bKeepRunning) { try { string msgLNG = null; lock (objLockSnapshot) { if (queueToStreamer.TryDequeue(out msgLNG)) { if (!String.IsNullOrEmpty(msgLNG)) { SocketPackage.SendData(msgLNG, ClientSocket); } //if (MDSUtils.shouldLog(lastLogTicks)) //{ // lastLogTicks = DateTime.Now.Ticks; // logger.Info("Mensagens na fila: " + queueToStreamer.Count); //} continue; } } Thread.Sleep(100); } catch (Exception ex) { logger.Error("queueProcessor(): " + ex.Message, ex); } } logger.Info("Finalizando processamento da fila de envio streamer de algoritmos"); }