static void SendTimer_Elapsed(object sender, System.Timers.ElapsedEventArgs e) { lock (SendBufferQueue) { int bufferCount = SendBufferQueue.Count; if (0 != bufferCount) { try { string dataStr = string.Empty; for (int i = 0; i < bufferCount; i++) { dataStr = SendBufferQueue.Dequeue(); TcpSocketCommunicator reporter = new TcpSocketCommunicator(); reporter.Connect(RelayServerInfo.Host_name, RelayServerInfo.Port_num, 5000); reporter.Send(Encoding.UTF8.GetBytes(dataStr)); reporter.Close(); //LogOutput.LogAppend("SendTimer_Elapsed Send : " + dataStr); Thread.Sleep(10); } } catch (Exception ex) { System.Diagnostics.Trace.WriteLine(ex.ToString()); LogOutput.LogAppend(ex.ToString()); } } } SendTimer.Start(); }
static void SendTimer_Elapsed(object sender, System.Timers.ElapsedEventArgs e) { while (true) { lock (SendBufferQueue) { if (0 == SendBufferQueue.Count) { break; } string dataStr = SendBufferQueue.Dequeue(); SendClientData2DB(dataStr); } } SendTimer.Start(); }