Cross thread operation to show a form

J

JB

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
 
G

Guest

Well i have no clue how your code looks like

but to synchronize i use this

Delegate Sub CrossThreadInvParaMC()

Public Sub Test()
If objectname.InvokeRequired Then
Dim d As New CrossThreadInvParaMC(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 )
 

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