public void Close()
{
Task task = TaskAsyncHelper.Empty;
lock (_lockObj)
{
if (ChangeState(StreamState.Closed))
{
_perfCounters.ScaleoutStreamCountOpen.RawValue = 0;
_perfCounters.ScaleoutStreamCountBuffering.RawValue = 0;
if (UsingTaskQueue)
{
// Ensure the queue is started
EnsureQueueStarted();
// Drain the queue to stop all sends
task = Drain(_queue, _logger);
}
}
}
if (UsingTaskQueue)
{
// Block until the queue is drained so no new work can be done
task.Wait();
}
}