I'm investigating a stack trace (seen while debugging) that looks something like the following:
MyUtility.AcquireLock()
[some of our code]
MyControl.OnPaint(PaintEventArgs e)
[some external WinForms (painting) code]
(native code corresponding to Monitor.Enter(object))
MyUtility.AcquireLock()
[some of our code]
MyControl.OnLoad(EventArgs e)
开发者_如何转开发
Does this make sense or did something screw up my stack trace?
I'm almost (but not completely) certain, no other thread is holding this lock, I'm trying to acquire (by using Monitor.Enter()).
It does. Monitor.Enter does a so called alertable wait. Only few people know what this means in 2011 because it is an obscure concept. It means that the thread will pump window messages while waiting. Yes, this seems grotesque. You are currently in a very dark world of pain because you are facing nondeterministic reentrancy issues.
The way to the light is to not wait on the gui thread at all! Start a background thread, maybe a BackgroundWorker.
精彩评论