Control.Invoke and multithreading

  • Thread starter Thread starter Zanna
  • Start date Start date
Z

Zanna

Hi all!

I got a little problem with multithreading.

I have a form with tree labels that create an instance of a class with a
new thread in it.
This new thread do some computation and then it raises an event of its
class that is trapped by the main form.

In this form I do this:


Private Delegate Sub SafeInvoker()

Public Sub Safe()
Me.Label1.Text = "ok"
Me.Label2.Text = "ok"
Me.Label3.Text = "ok"
End Sub


Private Sub MyThreadEvent(ByVal sender As Object, ByVal e As
EventArgs) Handles MyObj.MyThreadEvent
Dim del As New SafeInvoker(AddressOf Safe)
Me.Invoke(del)
End Sub


When I do Me.Invoke(del) I get ArgumentException.

Why?
How can I do it work?

Thanks
 
Daniel Moth ha scritto:
Control.Invoke accepts only the EventHandler delegate type in CF 1.0

Oh!
Well, I changed my declarations to

Private Delegate Sub SafeInvoker(ByVal sender As Object, ByVal e As
EventArgs)

Public Sub Safe(ByVal sender As Object, ByVal e As EventArgs)

But I still have an ArgumentException on the Me.Invoke(del)

What is going wrong again?

Thanks again :)
 
Hi

You are still passing your own delegate to Control.Invoke which will not
work (just changing the signature is not enough)

1. Comment out your delegate declaration and any reference to it
2. Replace your Me.Invoke(del) with Me.Invoke(New EventHandler(AddressOf
Safe))

Cheers
Daniel
 
Back
Top