none
C# ==> opening a new form ?!?!?!?!?! RRS feed

  • Question

  • This problem is not as simple as it sounds like.
    I have 2 forms "f1" and "f2" and a class called "c"

    inside f1 i instantiated an object of f2 and c
    anytime that i say f2.show() (inside f1) it shows the f2 form and it totally works fine

                                                       BUT

    inside the class c i have a reference to my main form (f1)
    so if i say f1.f2.show()  (inside c) then the form gets stock (white screen) (not responding) why is this happening

    _________________________________________________________________________________

    I thought if i use a thread when openning the new form inside my class that would fix the problem.
    but when i open the form in a new thread the form shows up for about a second and it disappears.
    It does exists but it's hidden (I can only open 1 instance of this form so when i try to open it again it says the form already exists but it's hidden)

    ANY SUGGESTIONS HERE?  (using .net 3.5 & vs2008)
    AG
    • Edited by aryaxt Thursday, November 13, 2008 4:53 PM
    Thursday, November 13, 2008 4:52 PM

Answers

  • Two reasons you'd get a dead form:

    - Calling Show() from any thread other then the UI thread.  Such a thread wouldn't pump a message loop (Application.Run) so the form doesn't get any paint events.
    - The main thread is busy executing code, not going idle.  It doesn't re-enter the message loop and thus doesn't dispatch Windows messages anymore.  Like WM_PAINT.



    Hans Passant.
    • Marked as answer by aryaxt Friday, November 14, 2008 6:20 AM
    Friday, November 14, 2008 12:09 AM
    Moderator
  • Sorry, but that's not a fix.  If App.Run() worked, you most likely called the Show() method from the wrong thread.  That thread won't be in the right state.  You should use Control.Invoke().
    Hans Passant.
    • Marked as answer by aryaxt Tuesday, November 25, 2008 4:32 PM
    Friday, November 14, 2008 10:48 AM
    Moderator

All replies

  • Two reasons you'd get a dead form:

    - Calling Show() from any thread other then the UI thread.  Such a thread wouldn't pump a message loop (Application.Run) so the form doesn't get any paint events.
    - The main thread is busy executing code, not going idle.  It doesn't re-enter the message loop and thus doesn't dispatch Windows messages anymore.  Like WM_PAINT.



    Hans Passant.
    • Marked as answer by aryaxt Friday, November 14, 2008 6:20 AM
    Friday, November 14, 2008 12:09 AM
    Moderator
  • nobugz said:

    Two reasons you'd get a dead form:

    - Calling Show() from any thread other then the UI thread.  Such a thread wouldn't pump a message loop (Application.Run) so the form doesn't get any paint events.
    - The main thread is busy executing code, not going idle.  It doesn't re-enter the message loop and thus doesn't dispatch Windows messages anymore.  Like WM_PAINT.



    Hans Passant.

    Application.Run fixed all my problems thank you

    AG
    • Edited by aryaxt Friday, November 14, 2008 6:23 AM
    Friday, November 14, 2008 6:21 AM
  • Sorry, but that's not a fix.  If App.Run() worked, you most likely called the Show() method from the wrong thread.  That thread won't be in the right state.  You should use Control.Invoke().
    Hans Passant.
    • Marked as answer by aryaxt Tuesday, November 25, 2008 4:32 PM
    Friday, November 14, 2008 10:48 AM
    Moderator