File tree Expand file tree Collapse file tree 2 files changed +25
-18
lines changed
Expand file tree Collapse file tree 2 files changed +25
-18
lines changed Original file line number Diff line number Diff line change @@ -21,7 +21,8 @@ public SoftSchedulerNotifyDebounce(Action<string> notifyCoreAction)
2121 }
2222
2323 /// <summary>
24- /// Debounces notifications; fires immediately when count == 0, otherwise after Debounce.
24+ /// Sends notifications in a thread-safe way and suppresses duplicates.
25+ /// Fires immediately for every change.
2526 /// </summary>
2627 internal void NotifySafely ( int count )
2728 {
@@ -30,16 +31,8 @@ internal void NotifySafely(int count)
3031 if ( Volatile . Read ( ref _disposed ) == 1 )
3132 return ;
3233
33- var due = ( count == 0 ) ? TimeSpan . Zero : Debounce ;
34-
35- try
36- {
37- _timer . Change ( due , Timeout . InfiniteTimeSpan ) ;
38- }
39- catch ( ObjectDisposedException )
40- {
41- // Raced with Dispose(); ignore.
42- }
34+ // Call immediately so the reported thread count stays in sync
35+ Callback ( null ) ;
4336 }
4437
4538 /// <summary>
@@ -75,4 +68,4 @@ public void Dispose()
7568 _timer . Dispose ( ) ;
7669 }
7770 }
78- }
71+ }
Original file line number Diff line number Diff line change @@ -53,11 +53,8 @@ public TickerQTaskScheduler(
5353 _workerQueues [ i ] = new ConcurrentQueue < WorkItem > ( ) ;
5454 }
5555
56- // Start all workers upfront to honor maxConcurrency
57- for ( int i = 0 ; i < _maxConcurrency ; i ++ )
58- {
59- TryStartWorker ( ) ;
60- }
56+ // Start at least one worker immediately to handle incoming tasks
57+ TryStartWorker ( ) ;
6158 }
6259
6360 /// <summary>
@@ -250,7 +247,24 @@ private async Task WorkerLoopCoreAsync(int workerId)
250247 // No work found - check if we should exit
251248 if ( DateTime . UtcNow - lastWorkTime > _idleWorkerTimeout )
252249 {
253- // Keep workers alive to maintain maxConcurrency; just reset timer
250+ // Check ALL queues for any remaining work before exiting
251+ bool anyWorkRemaining = false ;
252+ for ( int i = 0 ; i < _maxConcurrency ; i ++ )
253+ {
254+ if ( _workerQueues [ i ] . Count > 0 )
255+ {
256+ anyWorkRemaining = true ;
257+ break ;
258+ }
259+ }
260+
261+ // Only exit if there's really no work and we have minimum workers
262+ if ( ! anyWorkRemaining && _totalQueuedTasks == 0 && _activeWorkers > 1 )
263+ {
264+ break ; // Exit this worker
265+ }
266+
267+ // Reset timer if we need to stay
254268 lastWorkTime = DateTime . UtcNow ;
255269 }
256270
You can’t perform that action at this time.
0 commit comments