Is there any tool available to profile .Net Thread contention. I have added performance counter for threads for a windows Service which is running slow. It shows around 150
I ran into the same problem with a Visual Studio 2008 project, so I wasn't able to use VS2010's thread contention profiler. Instead, I wrote a diagnostic class, TimedMonitor, that tracks the amount of time spent waiting for locks.
To use it, you would replace:
object myLock = new object();
lock (myLock) { /* do work */ }
with:
TimedMonitor timedLock = new TimedMonitor();
using (timedLock.Lock()) { /* do work */ }
Console.WriteLine("Lock was entered {0} times; total wait time: {1}.",
timedLock.EnterCount, timedLock.WaitTime);
If you're only using a small number of simple locks (i.e., with Monitor.Enter or the lock keyword), replacing them with TimedMonitor and logging the output may help identify which lock is responsible for the most time spent waiting. However, if you're using more complex managed locks (e.g., ReaderWriterLock) or native synchronization (e.g., ManualResetEvent), it won't be helpful since it doesn't track those.
Not a profiler, but windbg with the sosex.dll extension can tell you what deadlocks you are having. Look for it here and read about the !dlk command.
Visual Studio 2010 has a thread contention profiler.