473,799 Members | 3,214 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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(A ddressOf ShowRecvdMessag e))

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.U til.RetrieveMes sage(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(A ddressOf ShowRecvdMessag e))

End If

End While

Catch e As Exception

multicastExcept ion(e)

End Try

End Sub
Nov 21 '05 #1
3 2244
Just a trick, see if it works,

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

HTH
rawCoder

"m.posseth" <mi*****@nohaus ystems.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(A ddressOf ShowRecvdMessag e))

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.U til.RetrieveMes sage(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(A ddressOf ShowRecvdMessag e))

End If

End While

Catch e As Exception

multicastExcept ion(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.U til.RetrieveMes sage(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(A ddressOf ShowRecvdMessag e))

End While

Catch e As Exception

multicastExcept ion(e)

End Try

End Sub

Thanks for helping me out

Regards

Michel Posseth


"rawCoder" <ra******@hotma il.com> wrote in message
news:%2******** ********@TK2MSF TNGP10.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*****@nohaus ystems.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(A ddressOf ShowRecvdMessag e))

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.U til.RetrieveMes sage(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(A ddressOf ShowRecvdMessag e))

End If

End While

Catch e As Exception

multicastExcept ion(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
1613
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 an instance of the server and invoke the send() method?
4
2815
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 secondary thread is aborted, then the MessageBox control does not get deleted. The forms do. I am unsure why this should be the case because MessageBox is also derived from System.Windows.Forms. Is there any way I can get the MessageBoxes to be...
4
2208
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 http://www.codeproject.com/csharp/winformsthreading.asp
5
1417
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 sense. However, using the control's Invoke method handles calling it's methods, but what about accessing the control's properties from another thread? What's the proper way to do that? -- John C. Bowman
4
7091
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 incoming connection,the relative code snipprt as following:: private IPAddress myIP=IPAddress.Parse("127.0.0.1"); private IPEndPoint myServer; private Socket socket; private Socket accSocket; private System.Windows.Forms.Button button2;...
2
26521
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 for a incoming connection,the relative code snipprt as following:: private IPAddress myIP=IPAddress.Parse("127.0.0.1");
10
1190
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 Thread(AddressOf SomeDatabaseProcess) t.Start()
2
998
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 Business object. I set this up so that it would run on a seperate thread since it is something like 2000 records that we are dealing with. The form has a progress bar that I would like to update with each row we import. The only problem is that...
2
3105
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 color of the text will depend upon the first argument and the text will be contained in the second argumet. As far as I know, my application is not multithreaded - at least I don't knowingly start any other threads. Since I don't know what the heck...
0
9688
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9546
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10490
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10030
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9078
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
6809
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5590
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4146
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3762
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.