By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
444,238 Members | 1,485 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 444,238 IT Pros & Developers. It's quick & easy.

multithread method invoke

P: n/a
Hello

does someone know how i can invoke a method in the underlying thread without
the usage of a window handle ??
This works perfect in a form

Me.Invoke(New MethodInvoker(AddressOf ShowRecvdMessage))

however in a control i receive the folowing error

"Cannot call Invoke or InvokeAsync on a control until the window handle has
been created."



the complete routine that runs on a background thread:

Private Sub Listener()

done = False

Try

While Not done

Dim iPEndPoint As IPEndPoint = Nothing

Dim bs As Byte() = client.Receive(iPEndPoint)

Dim m As IMessage = NHS.Messaging.Util.RetrieveMessage(bs)

If Not m Is Nothing Then 'Return

message = m.MessageText

' need to use Invoke or BeginInvoke Syntax as message is on different
thread--

Me.Invoke(New MethodInvoker(AddressOf ShowRecvdMessage))

End If

End While

Catch e As Exception

multicastException(e)

End Try

End Sub
Nov 21 '05 #1
Share this Question
Share on Google+
3 Replies


P: n/a
Just a trick, see if it works,

try doing dim nHandle as integer = Me.Handle
before the invoke line

HTH
rawCoder

"m.posseth" <mi*****@nohausystems.nl> wrote in message
news:42***********************@nova.planet.nl...
Hello

does someone know how i can invoke a method in the underlying thread without the usage of a window handle ??
This works perfect in a form

Me.Invoke(New MethodInvoker(AddressOf ShowRecvdMessage))

however in a control i receive the folowing error

"Cannot call Invoke or InvokeAsync on a control until the window handle has been created."



the complete routine that runs on a background thread:

Private Sub Listener()

done = False

Try

While Not done

Dim iPEndPoint As IPEndPoint = Nothing

Dim bs As Byte() = client.Receive(iPEndPoint)

Dim m As IMessage = NHS.Messaging.Util.RetrieveMessage(bs)

If Not m Is Nothing Then 'Return

message = m.MessageText

' need to use Invoke or BeginInvoke Syntax as message is on different
thread--

Me.Invoke(New MethodInvoker(AddressOf ShowRecvdMessage))

End If

End While

Catch e As Exception

multicastException(e)

End Try

End Sub

Nov 21 '05 #2

P: n/a
Well ,,,, after a slight conversion :-)
Dim nHandle As IntPtr = Me.Handle

This seems to work ( the error isn`t raised annymore , now see if it is
receiving data )

The problem is solved however i am still curious why it occured :-)

Private Sub Listener()

done = False

Try

While Not done

Dim iPEndPoint As IPEndPoint = Nothing

Dim bs As Byte() = client.Receive(iPEndPoint)

Dim m As IMessage = NHS.Messaging.Util.RetrieveMessage(bs)

If Not m Is Nothing Then Return

message = m.MessageText

Dim nHandle As IntPtr = Me.Handle

' need to use Invoke or BeginInvoke Syntax as message is on different
thread--

Me.Invoke(New MethodInvoker(AddressOf ShowRecvdMessage))

End While

Catch e As Exception

multicastException(e)

End Try

End Sub

Thanks for helping me out

Regards

Michel Posseth


"rawCoder" <ra******@hotmail.com> wrote in message
news:%2****************@TK2MSFTNGP10.phx.gbl...
Just a trick, see if it works,

try doing dim nHandle as integer = Me.Handle
before the invoke line

HTH
rawCoder

"m.posseth" <mi*****@nohausystems.nl> wrote in message
news:42***********************@nova.planet.nl...
Hello

does someone know how i can invoke a method in the underlying thread

without
the usage of a window handle ??
This works perfect in a form

Me.Invoke(New MethodInvoker(AddressOf ShowRecvdMessage))

however in a control i receive the folowing error

"Cannot call Invoke or InvokeAsync on a control until the window handle

has
been created."



the complete routine that runs on a background thread:

Private Sub Listener()

done = False

Try

While Not done

Dim iPEndPoint As IPEndPoint = Nothing

Dim bs As Byte() = client.Receive(iPEndPoint)

Dim m As IMessage = NHS.Messaging.Util.RetrieveMessage(bs)

If Not m Is Nothing Then 'Return

message = m.MessageText

' need to use Invoke or BeginInvoke Syntax as message is on different
thread--

Me.Invoke(New MethodInvoker(AddressOf ShowRecvdMessage))

End If

End While

Catch e As Exception

multicastException(e)

End Try

End Sub


Nov 21 '05 #3

P: n/a
I read this solution some times ago on the newsgroup and was in the back of
my mind, but I forgot the datatype catch.
Well I think someone said that this line forces the handle to be created.
If this is THE window handle, then its very strange.
Some one has recommended to call the CreateHandle/CreateControl method as
well.

HTH
rawCoder
Nov 21 '05 #4

This discussion thread is closed

Replies have been disabled for this discussion.