Every call to the web service goes through a custom queuing system. This has a limit that is set to 1. Every call that enters the same time with another call is purged and not handled. Not sure if this is completely thread safe.
public void QueueForExecution(T value)
{
lock (_queueLock)
{
if (_entryCount < _queueLimit)
{
Interlocked.Increment(ref _entryCount);
Logger.Trace(String.Format("Running task queue item for {0}.", _methodName));
Task.Run(() => RunTask(value));
}
else
{
lock (_queueItemLock)
{
_queuedExecutionValue = value;
}
Logger.Trace(String.Format("Task queue limit reached for {0} - queued request - overriding any previous queued items.", _methodName));
}
}
}