I am attempting to throttle the amount of messages I send to a SMPP SMC(server). I need to throttle them so the SMC does not throttle and drop my messages.
This is what I have tried:
double _client.SendSpeedLimit = 20;
if (Math.Abs(_client.SendSpeedLimit) > 1E-6 && _lastSubmit != DateTime.MinValue)
{
check submit speed and wait for next time
double elapsed = (DateTime.Now - _lastSubmit).TotalMilliseconds;
if (elapsed < 1000f / _client.SendSpeedLimit)
{
int interval = Convert.ToInt32((1000f / _client.SendSpeedLimit) - elapsed);
Thread.Sleep(interval);
}
}
and...
int left = (int)(start.AddSeconds(1.0 / (double)_client.SendSpeedLimit) - DateTime.UtcNow).TotalMilliseconds;
if (left > 0)
{
MobileDAL.InsertError(Settings.Default.MobileConnectionString, "Throttled: " + _clientFriendlyName, "", _AccountID);
Console.WriteLine("Throttled: " + _clientFriendlyName, "", _AccountID);
while (left > 0)
{
Thread.Sleep(10);
left = left - 10;
}
start = DateTime.UtcNow;
}
But they dont seem to work as expected because I still get throttled by the service provider(SMC). Is there something wrong with the code? Could someone offer points of improvement?