mirror of
https://gitee.com/ThingsGateway/ThingsGateway.git
synced 2025-10-27 13:47:10 +08:00
并行关闭线程
This commit is contained in:
@@ -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();
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user