1

I had a problem in .net compact 3.5 where my dialog closed immediately after being shown with .ShowDialog(). Then I found a workaround to call it twice. It helped, but I have no idea why. I mean why would executing the same operation twice would work any different, while the constructor code is only called once anyway.?

           try
            {
                //blinks the form (closes immediately)
                _activeChildView.ShowDialog();
                //shows dialog and blocks the thread until dialog is closed (woks as intended)
                _activeChildView.ShowDialog();
            }
            catch( Exception ex)
            {
                //no exception is ever caught there
            }

The first dialog result is DialogResult.None and the Closing event isn't called after the first showDialog.

Ernis
  • 645
  • 11
  • 22
  • show your _activeChildView constractor – Kram Aug 11 '15 at 13:23
  • it has single line: initilaizeComponent(). I think that if the problem were in the contructor the second ShowDialog call wouldn't work too? – Ernis Aug 11 '15 at 13:27
  • The problem is definitely not in the code you showed. Show more. – Igor Aug 11 '15 at 13:45
  • Well I am not sure what to show you guys.. If the problem was in the code, I would get a exception when creating the object, not when showing it. There are no events or code associated with visibility or window state. Normally calling showDialog for the second time would cause a InvalidOperationException, but now when I call it for the second time it works as intended.and the first one doesn't. – Ernis Aug 11 '15 at 13:57
  • Is the code you posted in an event handler? – Chris Dunaway Aug 11 '15 at 16:55
  • Yup, that is a button click. I feel it has something to do with a threading. Invoking the code from the UI thread solves the problem, but does not answer my question :) – Ernis Aug 12 '15 at 05:23

0 Answers0