473,326 Members | 2,010 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,326 software developers and data experts.

multithread method invoke

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
3 2216
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
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
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: Xerox | last post by:
The SmtpMail class has a static property to set the server and a static method to send an email. But if its static, how can it work in a multithreaded environment? Surely one would want to create...
4
by: Mystery Man | last post by:
We have developed a CSharp program that has a secondary thread that is used to perform background operations. This secondary thread may display some MessageBoxes or Forms. However, if the...
4
by: cybertof | last post by:
Hello, I have read the following article : "You cannot interact with UI elements from a thread that did not create them." The article comes from...
5
by: John Bowman | last post by:
Hi, I've read "Cybertof"'s thread (04/19/04) & the article he provided in a link about accessing UI elements from a thread that did not create them. What the authors are saying makes plenty of...
4
by: zbcong | last post by:
Hello: I write a multithread c# socket server,it is a winform application,there is a richtextbox control and button,when the button is click,the server begin to listen the socket port,waiting for a...
2
by: zhebincong | last post by:
Hello: I write a multithread c# socket server,it is a winform application,there is a richtextbox control and button,when the button is click,the server begin to listen the socket port,waiting...
10
by: Derek Hart | last post by:
On the main thread I have a status bar in a Windows form that I want to update when a long database process runs. The database process runs on a separate thread: Dim t As New...
2
by: GarrettD78 | last post by:
I have a form that I am upload rows into an SQL server database. The form has a button that when it is clicked creates a Custom Business Object and then calls the actually upload method from that...
2
by: =?Utf-8?B?UmF5IE1pdGNoZWxs?= | last post by:
Hello, Sorry for the long-winded dissertation - but, I have an application where I need to write text to a rich text box using a common method, callable from anywhere in my application. The...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.