开发者

Performance counters and threading

开发者 https://www.devze.com 2022-12-16 20:57 出处:网络
I am creating some custom performance counters.I will be creating tasks on a thread pool and inc开发者_运维问答rementing/decrementing the counters from within multiple worker threads.

I am creating some custom performance counters. I will be creating tasks on a thread pool and inc开发者_运维问答rementing/decrementing the counters from within multiple worker threads.

Do I need to give each thread a new counter object? Is it safe to share a performance counter object cross-thread (for increment/decrement)


The PerformanceCounter class already uses a threadsafe wrapper, an internal class named SharedPerformanceCounter. It uses Interlocked.Increment() to increment a counter value for example.

There's no need to lock yourself.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号