Login  
Search All Forums
Dart Home | PowerTCP Sockets for .NET | Custom Development Reply | PowerTCP Sockets for .NET (Secure and Standard) Topics | Forums   
AuthorForum: PowerTCP Sockets for .NET (Secure and Standard)
Topic: udp threading issue
corpse

From: LITH, IL USA
Posts: 6
Member Since: 04/23/04
posted April 23, 2004 1:21 PM

I am doing a simple peer-to-peer type messaging system in my order entry system, and I'm using the udp .net component to achieve this.

First, in the form load event, I do:
' Listen for datagrams on port 7.
ctlUDP.Open(7)
' Begin an asynchronous Receive
Dim buffer(ctlUDP.BufferSize) As Byte
ctlUDP.BeginReceive(buffer)

Then, to SEND data, from my button click, I do:
ctlUDP.Send(oPackage.XML, oComputerTarget.HostIP, 7)

opackage.xml returns a string, and the ocomputertarget.hostip returns a string of the ip.

After this, the ctlUDP_EndReceive is called, the code for that is:

Server_DataArrival(e.Datagram.ToString())
Dim buffer(ctlUDP.BufferSize) As Byte
ctlUDP.BeginReceive(buffer)


Server_DataArrival is a routine that simply parses the XML received in the datagram, and might do something (like write data to a database and display a msgbox on the screen). For testing, I'm doing this test and sending on the same machine.

The error I get is:
  Message: "The action being performed on this control is being called from the wrong thread. You must marshal to the correct thread using Control.Invoke or Control.BeginInvoke to perform this action."
  Source: "System.Windows.Forms"
  StackTrace: "  at System.Windows.Forms.TreeNode.Realize()
  at System.Windows.Forms.TreeNodeCollection.Add(TreeNode node)
  at isrMessaging.frmCommunicator.Server_DataArrival(String Data) in C:\Data\xxx\frmCommunicator.vb:line 676"
  TargetSite: {System.Reflection.RuntimeMethodInfo}

it is failing on this line:
ndIncomingMessages.Nodes.Add(ndPackage)

It's important for the app to write back to the UI, but the threaded nature of the UDP component seems to prevent me from doing so.

Thanks for the help, and your patience reading such a detailed message :) 
Tom
corpse

From: LITH, IL USA
Posts: 6
Member Since: 04/23/04
posted April 23, 2004 2:18 PM

nevermind - I got it! I kept missing SynchronizingObject.
Reply | PowerTCP Sockets for .NET (Secure and Standard) Topics | Forums   
This site is powered by PowerTCP WebServer Tool PowerTCP WebServer for ActiveX