22
33using TaskMonitoring . Application . Models ;
44
5- namespace TaskMonitoring . Application ;
6-
7- public class ThreadPoolMonitor : IThreadPoolMonitor
5+ namespace TaskMonitoring . Application
86{
9- /// <summary>
10- /// Retrieves the total number of active threads in the thread pool.
11- /// </summary>
12- /// <returns>The current active thread count in the thread pool.</returns>
13- public int GetActiveThreadCount ( )
7+ public class ThreadPoolMonitor : IThreadPoolMonitor
148 {
15- return ThreadPool . ThreadCount ;
16- }
9+ /// <summary>
10+ /// Retrieves the total number of active threads in the thread pool.
11+ /// </summary>
12+ /// <returns>The current active thread count in the thread pool.</returns>
13+ public int GetActiveThreadCount ( )
14+ {
15+ // Fix: Replace ThreadPool.ThreadCount with a custom implementation
16+ ThreadPool . GetAvailableThreads ( out int workerThreads , out int ioThreads ) ;
17+ ThreadPool . GetMaxThreads ( out int maxWorkerThreads , out int maxIoThreads ) ;
1718
18- /// <summary>
19- /// Retrieves the current status of the thread pool, including the number of available worker and IO threads.
20- /// </summary>
21- /// <returns>A ThreadPoolStatus object containing the number of available worker and IO threads.</returns>
22- public ThreadPoolStatus GetThreadPoolStatus ( )
23- {
24- ThreadPool . GetAvailableThreads ( out int workerThreads , out int ioThreads ) ;
25- return new ThreadPoolStatus { WorkerThreadsAvailable = workerThreads , IoThreadsAvailable = ioThreads } ;
26- }
19+ int activeWorkerThreads = maxWorkerThreads - workerThreads ;
20+ int activeIoThreads = maxIoThreads - ioThreads ;
2721
28- /// <summary>
29- /// Sets the minimum number of threads that the thread pool maintains for worker and IO threads.
30- /// </summary>
31- /// <param name="threadPoolStatus">The minimum number of worker threads and the minimum number of IO threads.</param>
32- public void SetMinThreads ( ThreadPoolStatus threadPoolStatus )
33- {
34- ThreadPool . SetMinThreads ( threadPoolStatus . WorkerThreadsAvailable , threadPoolStatus . IoThreadsAvailable ) ;
35- }
22+ return activeWorkerThreads + activeIoThreads ;
23+ }
3624
37- /// <summary>
38- /// Sets the maximum number of threads that the thread pool can maintain for worker and IO threads.
39- /// </summary>
40- /// <param name="threadPoolStatus">The maximum number of worker threads and the maximum number of IO threads.</param>
41- public void SetMaxThreads ( ThreadPoolStatus threadPoolStatus )
42- {
43- ThreadPool . SetMaxThreads ( threadPoolStatus . WorkerThreadsAvailable , threadPoolStatus . IoThreadsAvailable ) ;
25+ /// <summary>
26+ /// Retrieves the current status of the thread pool, including the number of available worker and IO threads.
27+ /// </summary>
28+ /// <returns>A ThreadPoolStatus object containing the number of available worker and IO threads.</returns>
29+ public ThreadPoolStatus GetThreadPoolStatus ( )
30+ {
31+ ThreadPool . GetAvailableThreads ( out int workerThreads , out int ioThreads ) ;
32+ return new ThreadPoolStatus { WorkerThreadsAvailable = workerThreads , IoThreadsAvailable = ioThreads } ;
33+ }
34+
35+ /// <summary>
36+ /// Sets the minimum number of threads that the thread pool maintains for worker and IO threads.
37+ /// </summary>
38+ /// <param name="threadPoolStatus">The minimum number of worker threads and the minimum number of IO threads.</param>
39+ public void SetMinThreads ( ThreadPoolStatus threadPoolStatus )
40+ {
41+ ThreadPool . SetMinThreads ( threadPoolStatus . WorkerThreadsAvailable , threadPoolStatus . IoThreadsAvailable ) ;
42+ }
43+
44+ /// <summary>
45+ /// Sets the maximum number of threads that the thread pool can maintain for worker and IO threads.
46+ /// </summary>
47+ /// <param name="threadPoolStatus">The maximum number of worker threads and the maximum number of IO threads.</param>
48+ public void SetMaxThreads ( ThreadPoolStatus threadPoolStatus )
49+ {
50+ ThreadPool . SetMaxThreads ( threadPoolStatus . WorkerThreadsAvailable , threadPoolStatus . IoThreadsAvailable ) ;
51+ }
4452 }
45- }
53+ }
54+
0 commit comments