private void SendMessages()
{
lock (SendingSync)
{
try
{
ReportPeriodicInfoAllSessions();
while (true)
{
string packet = null;
lock (Sync)
{
if (_packet.Length == 0)
{
if (_messages.Count == 0)
return;
BuildPacket();
}
packet = _packet.ToString();
}
SendPacket(Url, AccessKey, ApplicationKey, packet);
lock (Sync)
{
_packet.Clear(); // clear packet only if succeeded
}
}
}
catch (ThreadInterruptedException)
{
}
catch (Exception exc)
{
Log("Exception", exc.ToString());
}
}
}