Im using locking object in my application with multiple threads.
How i can check how many times other threads tried to work on locked object, or how much time i wasted on trying to update locked object?
My code is based on best answer here:
Mutliple threads updating array
Edit: code copied over:
float[] bestResult;
object sync = new Object();
lock (sync)
{
if (bestResult[0] > calculatedData[0]) {
bestResult = calculatedData;
}
}
The System.Diagnostics.Stopwatch
class may help you here:
float[] bestResult;
object sync = new Object();
var sw = new System.Diagnostics.Stopwatch();
sw.Start();
lock (sync)
{
sw.Stop();
if (bestResult[0] > calculatedData[0]) {
bestResult = calculatedData;
}
}
Console.WriteLine("Time spent waiting: " + sw.Elapsed);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With