I am creating some custom performance counters. I will be creating tasks on a thread pool and incrementing/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.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.