@@ -320,26 +320,29 @@ private void AssignWork()
320
320
Interlocked . Decrement ( ref waitingWorkCount ) ;
321
321
}
322
322
}
323
+ }
323
324
324
- if ( waitingWorkID == null || work == null )
325
- {
326
- Interlocked . Exchange ( ref workerState , 0 ) ;
325
+ if ( waitingWorkID == null || work == null )
326
+ {
327
+ Interlocked . Exchange ( ref workerState , 0 ) ;
327
328
328
- Interlocked . Decrement ( ref powerPool . runningWorkerCount ) ;
329
- PowerPoolOption powerPoolOption = powerPool . PowerPoolOption ;
329
+ Interlocked . Decrement ( ref powerPool . runningWorkerCount ) ;
330
+ PowerPoolOption powerPoolOption = powerPool . PowerPoolOption ;
330
331
331
- powerPool . idleWorkerDic [ this . ID ] = this ;
332
- powerPool . idleWorkerQueue . Enqueue ( this . ID ) ;
332
+ powerPool . idleWorkerDic [ this . ID ] = this ;
333
+ powerPool . idleWorkerQueue . Enqueue ( this . ID ) ;
333
334
334
- powerPool . CheckPoolIdle ( ) ;
335
+ powerPool . CheckPoolIdle ( ) ;
335
336
336
- if ( powerPoolOption . DestroyThreadOption != null && powerPool . IdleWorkerCount > powerPoolOption . DestroyThreadOption . MinThreads )
337
+ if ( powerPoolOption . DestroyThreadOption != null && powerPool . IdleWorkerCount > powerPoolOption . DestroyThreadOption . MinThreads )
338
+ {
339
+ this . killTimer = new System . Timers . Timer ( powerPoolOption . DestroyThreadOption . KeepAliveTime ) ;
340
+ try
337
341
{
338
- this . killTimer = new System . Timers . Timer ( powerPoolOption . DestroyThreadOption . KeepAliveTime ) ;
339
- try
342
+ killTimer . AutoReset = false ;
343
+ killTimer . Elapsed += ( s , e ) =>
340
344
{
341
- killTimer . AutoReset = false ;
342
- killTimer . Elapsed += ( s , e ) =>
345
+ if ( powerPool . IdleWorkerCount > powerPoolOption . DestroyThreadOption . MinThreads )
343
346
{
344
347
SpinWait . SpinUntil ( ( ) =>
345
348
{
@@ -349,33 +352,26 @@ private void AssignWork()
349
352
int originalState = Interlocked . CompareExchange ( ref workerState , 2 , 0 ) ;
350
353
if ( originalState == 0 )
351
354
{
352
- if ( powerPool . IdleWorkerCount > powerPoolOption . DestroyThreadOption . MinThreads && powerPool . idleWorkerDic . TryRemove ( ID , out _ ) )
355
+ powerPool . idleWorkerDic . TryRemove ( ID , out _ ) ;
356
+ if ( powerPool . aliveWorkerDic . TryRemove ( ID , out _ ) )
353
357
{
354
- if ( powerPool . aliveWorkerDic . TryRemove ( ID , out _ ) )
355
- {
356
- Interlocked . Decrement ( ref powerPool . aliveWorkerCount ) ;
357
- powerPool . aliveWorkerList = powerPool . aliveWorkerDic . Values ;
358
- }
359
- Kill ( ) ;
360
-
361
- killTimer . Enabled = false ;
358
+ Interlocked . Decrement ( ref powerPool . aliveWorkerCount ) ;
359
+ powerPool . aliveWorkerList = powerPool . aliveWorkerDic . Values ;
362
360
}
361
+ Kill ( ) ;
363
362
}
364
- else
365
- {
366
- killTimer . Enabled = false ;
367
- }
368
- } ;
363
+ }
364
+ killTimer . Enabled = false ;
365
+ } ;
369
366
370
- killTimer . Start ( ) ;
371
- }
372
- catch
373
- {
374
- }
367
+ killTimer . Start ( ) ;
368
+ }
369
+ catch
370
+ {
375
371
}
376
-
377
- return ;
378
372
}
373
+
374
+ return ;
379
375
}
380
376
}
381
377
0 commit comments