Exemplo n.º 1
0
        public ThreadPoolLogger()
        {
            _BroadCastBlock          = new BroadcastBlock <ThreadPoolStats>(MapFunc);
            _cancellationTokenSource = new CancellationTokenSource();

            _workerThread = new Thread(async source =>
            {
                var token = (CancellationToken)source;
                while (token.IsCancellationRequested == false)
                {
                    ThreadPool.GetAvailableThreads(out int workerThreads, out int completionPortThreads);
                    ThreadPool.GetMaxThreads(out int maxWorkerThreads, out int maxCompletionPortThreads);
                    ThreadPool.GetMinThreads(out int minWorkerThreads, out int minCompletionPortThreads);

                    var stats = new ThreadPoolStats
                    {
                        AvailableWorkerThreads         = workerThreads,
                        AvailableCompletionPortThreads = completionPortThreads,
                        MaxWorkerThreads         = maxWorkerThreads,
                        MaxCompletionPortThreads = maxCompletionPortThreads,
                        MinWorkerThreads         = minWorkerThreads,
                        MinCompletionPortThreads = minCompletionPortThreads
                    };

                    _BroadCastBlock.SendAsync(stats).GetAwaiter().GetResult();

                    await Task.Delay(10, token).ConfigureAwait(false);
                }
            })
            {
                IsBackground = true,
                Priority     = ThreadPriority.AboveNormal
            };
        }
Exemplo n.º 2
0
 private ThreadPoolStats MapFunc(ThreadPoolStats arg)
 {
     return(new ThreadPoolStats()
     {
         DateTime = new DateTimeOffset(year: arg.DateTime.Year, month: arg.DateTime.Month, day: arg.DateTime.Day, hour: arg.DateTime.Hour, minute: arg.DateTime.Minute, second: arg.DateTime.Second, millisecond: arg.DateTime.Millisecond, offset: new TimeSpan(days: arg.DateTime.Offset.Days, hours: arg.DateTime.Offset.Hours, minutes: arg.DateTime.Offset.Minutes, seconds: arg.DateTime.Offset.Seconds, milliseconds: arg.DateTime.Offset.Milliseconds)),
         AvailableWorkerThreads = arg.AvailableWorkerThreads,
         AvailableCompletionPortThreads = arg.AvailableCompletionPortThreads,
         MaxWorkerThreads = arg.MaxWorkerThreads,
         MaxCompletionPortThreads = arg.MaxCompletionPortThreads,
         MinWorkerThreads = arg.MinWorkerThreads,
         MinCompletionPortThreads = arg.MinCompletionPortThreads
     });
 }