Some kind of deadlock in Control::SetParentHandle

K

Kenny Carruthers

Just wondering if someone could shed some light on what might be causing
the following problem:

I have a main window that is an MdiContainer. There is a "Windows" menu
that I populate myself and handle the events.
The problem is that every once in awhile, my application deadlocks when the
user selects a window from the menu and
the application tries to show() it. The code for showing it does nothing for
then look through an ArrayList of windows, finds the one
matching name, then calls:

(Handle in a basic menu_click event handler in the MDI Parent form)

window.MdiParent = this;
window.Show();

Right after the Show(), the application freezes. If I "Pause" it in the
debugger at this state, the CallStack
is the following:

system.windows.forms.dll!System.Windows.Forms.Control::SetParentHandle
system.windows.forms.dll!System.Windows.Forms.Control::CreateControl
system.windows.forms.dll!System.Windows.Forms.Control::CreateControl
system.windows.forms.dll!System.Windows.Forms.Control::WmShowWindow
system.windows.forms.dll!System.Windows.Forms.Control::WndProc
system.windows.forms.dll!System.Windows.Forms.ScrollableControl::WndProc
system.windows.forms.dll!System.Windows.Forms.ContainerControl::WndProc
system.windows.forms.dll!System.Windows.Forms.Form::WmShowWindow
system.windows.forms.dll!System.Windows.Forms.Form::WndProc
system.windows.forms.dll!ControlNativeWindow::OnMessage
system.windows.forms.dll!ControlNativeWindow::WndProc
system.windows.forms.dll!System.Windows.Forms.NativeWindow::DebuggableCallba
ck
system.windows.forms.dll!System.Windows.Forms.UnsafeNativeMethods::CreateWin
dowEx
system.windows.forms.dll!System.Windows.Forms.NativeWindow::CreateHandle
system.windows.forms.dll!System.Windows.Forms.Control::CreateHandle
system.windows.forms.dll!System.Windows.Forms.Form::CreateHandle
system.windows.forms.dll!System.Windows.Forms.Control::get_Handle
system.windows.forms.dll!System.Windows.Forms.Form::SetVisibleCore
system.windows.forms.dll!System.Windows.Forms.Control::set_Visible
system.windows.forms.dll!System.Windows.Forms.Control::Show()
EPro.exe!D2Pro.MainWindow.WindowsContainerMenuItem_Click

There's nothing fancy going on when I show this window that I can see
would cause a deadlock in my code.
The only thing that I can think of, is that one of the controls in the
window being show'n makes some InterOp
calls in its OnPaint() routine and uses the handle to the device context for
calling a few routines. Could this be causing the
call stack above?

Since this doesn't happen all the time, it's proving to be pretty
challenging to track down. Any help would be appreciated.

Thank you,
Kenny
 
Joined
Oct 24, 2006
Messages
2
Reaction score
0
Re: SetParentHandle

Hey Kenny - This is two and a half years later and I am having an identical issue as you. I have slightly more information. When I call ShowDialog, the form deadlocks only when i have a label with AutoSize=True.

This makes no sense to me but I'm still looking into it. I've seen deadlocks before with multi-threaded apps (which mine is) when Invoke isn't used when updating controls from other threads, but I'm not sure if that is the issue or not since I've pretty much encapsulated anything like that.

I'll reply again if I figure out the issue for posterity.
 
Joined
Oct 24, 2006
Messages
2
Reaction score
0
Ok - my last post helped me think about it. The problem is related to everything I discussed before. I create a global form so that different parts of my program can add output to it. Unfortunately I was not explicit about when the form is created, so the form was created by the first thread that accessed it - which happened to be a data thread and not the GUI thread. Why the Label's AutoSize affects this I am not sure, but it helped to debug the issue. :)

So my fix was to move the creation of the form into my main form's Load event and everything was golden. I think MSVS.NET 2005 catches these errors but we haven't quite migrated yet. (We'll probably finish just in time for the next version to be released.)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top