Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can request the locks and deadlocks of a thread at runtime with C#?

In Java there are ThreadMXBean and ThreadInfo to requests information over the locks that a thread is holding at runtime.

Is this also possible with C#? If yes how can I do it?

like image 591
Horcrux7 Avatar asked Nov 14 '22 07:11

Horcrux7


1 Answers

There isn't a runtime equivalent in C#. If you need to track it you'll need to implement you're own wrapper around it. Also consider using Monitor.TryEnter with a timeout if your application is sensitive to locking.

lock (object) { // Synchronized code }

Translates to,

try
{
    Monitor.Enter(object);
}
finally
{
    Monitor.Exit(object);
}

like image 191
M Afifi Avatar answered Nov 16 '22 02:11

M Afifi