并行关闭线程

This commit is contained in:
2248356998 qq.com
2023-06-12 14:41:08 +08:00
parent 42cf5e7a81
commit fa42cc1f00

View File

@@ -220,7 +220,9 @@ public class CollectDeviceWorker : BackgroundService
/// </summary>
private void RemoveAllDeviceThread()
{
foreach (var deviceThread in CollectDeviceThreads)
ParallelOptions options = new ParallelOptions();
options.MaxDegreeOfParallelism = Environment.ProcessorCount / 2;
Parallel.ForEach(CollectDeviceThreads, options, deviceThread =>
{
try
{
@@ -230,7 +232,7 @@ public class CollectDeviceWorker : BackgroundService
{
_logger?.LogError(ex, deviceThread.ToString());
}
}
});
CollectDeviceThreads.Clear();
}