Cross thread operation to show a form

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • JB

    #1

    Cross thread operation to show a form

    Hi All,

    I have a form (CFormMain) with a button. When I click the button, I
    call a remote server that performs some action and sometimes notifies
    back the client by displaying a custom message box (The custom message
    box is just another form displayed via a ShowDialog). I'd like to make
    my CFormMain form the owner of my message box, but when I specify it
    as the owner in the ShowDialog, I get an exception "Cross-thread
    operation not valid: Control 'CFormMain' accessed from a thread other
    than the thread it was created on."

    I understand the Message Box form is created in another thread, so I
    tried to use Invoke, but didn't get much luck. Is what I'm trying to
    do possible at all?

    Thanks
    JB

  • =?Utf-8?B?TWljaGVsIFBvc3NldGggW01DUF0=?=

    #2
    RE: Cross thread operation to show a form

    Well i have no clue how your code looks like

    but to synchronize i use this

    Delegate Sub CrossThreadInvP araMC()

    Public Sub Test()
    If objectname.Invo keRequired Then
    Dim d As New CrossThreadInvP araMC(AddressOf Test)
    Me.Invoke(d, Nothing)
    Else
    'do whatever you want to do
    End If
    End Sub

    and this works fine here ( asynchronous delegates and seperate threads that
    comunicate to 1 gui to to show whats happening to the user )





    "JB" wrote:
    Hi All,
    >
    I have a form (CFormMain) with a button. When I click the button, I
    call a remote server that performs some action and sometimes notifies
    back the client by displaying a custom message box (The custom message
    box is just another form displayed via a ShowDialog). I'd like to make
    my CFormMain form the owner of my message box, but when I specify it
    as the owner in the ShowDialog, I get an exception "Cross-thread
    operation not valid: Control 'CFormMain' accessed from a thread other
    than the thread it was created on."
    >
    I understand the Message Box form is created in another thread, so I
    tried to use Invoke, but didn't get much luck. Is what I'm trying to
    do possible at all?
    >
    Thanks
    JB
    >
    >

    Comment

    Working...