Results 1 to 3 of 3

Thread: ShowDialiog not working

  1. #1

    Thread Starter
    Hyperactive Member Teseng's Avatar
    Join Date
    Sep 2007
    Location
    Tupelo, MS
    Posts
    281

    ShowDialiog not working

    I am receiving data from a socket, which is on its own thread, it handles everything, and then passes the data to a routine on the main form, which calls ShowDialog(Me) when the first byte of data arrives. THe problem is, the ShowDialog, doesnt work. Its acting like i just used Show instead of ShowDialog, i can still work the form behind it just fine, which is bad. Is there anyway i can fix this??

  2. #2
    Raging swede Atheist's Avatar
    Join Date
    Aug 2005
    Location
    Sweden
    Posts
    8,018

    Re: ShowDialiog not working

    Thats because the two forms are displayed on separate threads. Create a subroutine that creates and displays the form using ShowDialog, and then do some cross-thread calls to invoke this method on the main thread. If you do not know how to perform cross-thread calls, take a look at this CodeBank submission by jmcilhinney.
    Rate posts that helped you. I do not reply to PM's with coding questions.
    How to Get Your Questions Answered
    Current project: tunaOS
    Me on.. BitBucket, Google Code, Github (pretty empty)

  3. #3

    Thread Starter
    Hyperactive Member Teseng's Avatar
    Join Date
    Sep 2007
    Location
    Tupelo, MS
    Posts
    281

    Re: ShowDialiog not working

    Thanks Athiest, after reading and a bit of googling, i figured out the problem. I was already passing the tcp events to the main thread, so i THOUGHT.

    The problem code was:

    Code:
    If frmMain.InvokeRequired Then
       frmMain.Invoke MySub
    else
       frmMain.MySub
    End if
    Which, apparently because it was on its own thread, it was creating a new class of frmMain, which didnt require an invoke. I fixed it with the following code
    Code:
    Dim MainFrm As frmMain = CType(Application.OpenForms(0), frmMain)
    If MainFrm.InvokeRequired Then
       MainFrm.Invoke MySub
    else
       MainFrm.MySub
    End if

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width