How to detect whether an EventWaitHandle is waiting?

Posted by AngryHacker on Stack Overflow See other posts from Stack Overflow or by AngryHacker
Published on 2010-03-12T23:26:19Z Indexed on 2010/03/12 23:27 UTC
Read the original article Hit count: 234

I have a fairly well multi-threaded winforms app that employs the EventWaitHandle in a number of places to synchronize access.

So I have code similar to this:

List<int> _revTypes;
EventWaitHandle _ewh = new EventWaitHandle(false, EventResetMode.ManualReset);

void StartBackgroundTask() {
    _ewh.Reset();
    Thread t = new Thread(new ThreadStart(LoadStuff));
    t.Start();
}

void LoadStuff() {
    _revTypes = WebServiceCall.GetRevTypes()
    // ...bunch of other calls fetching data from all over the place
    // using the same pattern
    _ewh.Set();
}


List<int> RevTypes {
    get {
        _ewh.WaitOne();
        return _revTypes;
    }
}

Then I just call .RevTypes somewehre from the UI and it will return data to me when LoadStuff has finished executing.

All this works perfectly correctly, however RevTypes is just one property - there are actually several dozens of these. And one or several of these properties are holding up the UI from loading in a fast manner.

Short of placing benchmark code into each property, is there a way to see which property is holding the UI from loading? Is there a way to see whether the EventWaitHandle is forced to actually wait?

© Stack Overflow or respective owner

Related posts about event-wait-handle

Related posts about c#3.0