Reformat and apply Stylecop rules

This commit is contained in:
ta264
2019-12-22 22:08:53 +00:00
committed by Qstick
parent d4fa9b7345
commit f02fa629cc
1186 changed files with 7105 additions and 5616 deletions
@@ -11,12 +11,15 @@ namespace NzbDrone.Common.TPL
/// <summary>Whether the current thread is processing work items.</summary>
[ThreadStatic]
private static bool _currentThreadIsProcessingItems;
/// <summary>The list of tasks to be executed.</summary>
private readonly LinkedList<Task> _tasks = new LinkedList<Task>(); // protected by lock(_tasks)
private readonly LinkedList<Task> _tasks = new LinkedList<Task>();
/// <summary>The maximum concurrency level allowed by this scheduler.</summary>
private readonly int _maxDegreeOfParallelism;
/// <summary>Whether the scheduler is currently processing work items.</summary>
private int _delegatesQueuedOrRunning = 0; // protected by lock(_tasks)
private int _delegatesQueuedOrRunning = 0;
/// <summary>
/// Initializes an instance of the LimitedConcurrencyLevelTaskScheduler class with the
@@ -25,7 +28,11 @@ namespace NzbDrone.Common.TPL
/// <param name="maxDegreeOfParallelism">The maximum degree of parallelism provided by this scheduler.</param>
public LimitedConcurrencyLevelTaskScheduler(int maxDegreeOfParallelism)
{
if (maxDegreeOfParallelism < 1) throw new ArgumentOutOfRangeException("maxDegreeOfParallelism");
if (maxDegreeOfParallelism < 1)
{
throw new ArgumentOutOfRangeException("maxDegreeOfParallelism");
}
_maxDegreeOfParallelism = maxDegreeOfParallelism;
}
@@ -78,11 +85,15 @@ namespace NzbDrone.Common.TPL
}
// Execute the task we pulled out of the queue
base.TryExecuteTask(item);
TryExecuteTask(item);
}
}
// We're done processing items on the current thread
finally { _currentThreadIsProcessingItems = false; }
finally
{
_currentThreadIsProcessingItems = false;
}
}, null);
}
@@ -93,13 +104,19 @@ namespace NzbDrone.Common.TPL
protected sealed override bool TryExecuteTaskInline(Task task, bool taskWasPreviouslyQueued)
{
// If this thread isn't already processing a task, we don't support inlining
if (!_currentThreadIsProcessingItems) return false;
if (!_currentThreadIsProcessingItems)
{
return false;
}
// If the task was previously queued, remove it from the queue
if (taskWasPreviouslyQueued) TryDequeue(task);
if (taskWasPreviouslyQueued)
{
TryDequeue(task);
}
// Try to run the task.
return base.TryExecuteTask(task);
return TryExecuteTask(task);
}
/// <summary>Attempts to remove a previously scheduled task from the scheduler.</summary>
@@ -107,7 +124,10 @@ namespace NzbDrone.Common.TPL
/// <returns>Whether the task could be found and removed.</returns>
protected sealed override bool TryDequeue(Task task)
{
lock (_tasks) return _tasks.Remove(task);
lock (_tasks)
{
return _tasks.Remove(task);
}
}
/// <summary>Gets the maximum concurrency level supported by this scheduler.</summary>
@@ -121,12 +141,21 @@ namespace NzbDrone.Common.TPL
try
{
Monitor.TryEnter(_tasks, ref lockTaken);
if (lockTaken) return _tasks.ToArray();
else throw new NotSupportedException();
if (lockTaken)
{
return _tasks.ToArray();
}
else
{
throw new NotSupportedException();
}
}
finally
{
if (lockTaken) Monitor.Exit(_tasks);
if (lockTaken)
{
Monitor.Exit(_tasks);
}
}
}
}