moved wait to finally block

This commit is contained in:
Greg Lutz
2015-06-26 09:31:31 -04:00
parent 460aa3229e
commit 569b2711cc

View File

@@ -319,9 +319,13 @@ namespace TimberWinR.Outputs
_batchCounter.SampleQueueDepth(_jsonQueue.Count);
// Re-compute current batch size
LogManager.GetCurrentClassLogger().Trace("{0}: Average Queue Depth: {1}, Current Length: {2}", Thread.CurrentThread.ManagedThreadId, _batchCounter.AverageQueueDepth(), _jsonQueue.Count);
LogManager.GetCurrentClassLogger()
.Trace("{0}: Average Queue Depth: {1}, Current Length: {2}",
Thread.CurrentThread.ManagedThreadId, _batchCounter.AverageQueueDepth(),
_jsonQueue.Count);
_currentBatchCount = _batchCounter.UpdateCurrentBatchCount(_jsonQueue.Count, _currentBatchCount);
_currentBatchCount = _batchCounter.UpdateCurrentBatchCount(_jsonQueue.Count,
_currentBatchCount);
messages = _jsonQueue.Take(_currentBatchCount).ToArray();
_jsonQueue.RemoveRange(0, messages.Length);
@@ -342,7 +346,9 @@ namespace TimberWinR.Outputs
{
client.StartPipe();
LogManager.GetCurrentClassLogger()
.Debug("{0}: Sending {1} Messages to {2}", Thread.CurrentThread.ManagedThreadId, messages.Length, client.Host);
.Debug("{0}: Sending {1} Messages to {2}",
Thread.CurrentThread.ManagedThreadId, messages.Length,
client.Host);
try
{
@@ -395,8 +401,6 @@ namespace TimberWinR.Outputs
}
}
}
if (!Stop)
syncHandle.Wait(TimeSpan.FromMilliseconds(_interval), CancelToken);
}
catch (OperationCanceledException)
{
@@ -412,6 +416,17 @@ namespace TimberWinR.Outputs
Interlocked.Increment(ref _errorCount);
LogManager.GetCurrentClassLogger().Error(ex);
}
finally
{
try
{
if (!Stop)
syncHandle.Wait(TimeSpan.FromMilliseconds(_interval), CancelToken);
}
catch (Exception)
{
}
}
}
}
}