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: To Thread or not to Thread
computeronsite

From: Calgary, AB Canada
Posts: 45
Member Since: 06/12/02
posted May 23, 2004 3:23 PM

Been using Visual Basic for years, and recently purchased Visual Basic.net
Im new to the BeginInvoke statements
Im experimenting with your sockets for .net
ive read through the echo server sample and am using it as my template with a few changes.

If i need to call an external sub procedure from within the try loop for the connection event do i have to use the begininvoke to stay on the same thread? Example:

Try  
Do While e.Tcp.Connected
InComingData = e.Tcp.Receive.ToString()
Do
Call ExternalSubHere(Data,ReturnData)
REM will seperate data and exit loop when done 
Loop Until Rerturndata = ""
Loop
Catch ex As Exception 
Finally 
End Try
Tony Priest



From: Utica, NY USA
Posts: 8466
Member Since: 04/11/00
posted May 24, 2004 9:36 AM

The reason we us BeginInvoke is to provide thread safety. Since there is a possiblity that two events could fire at the exact same time and the events output data to the same textbox.
computeronsite

From: Calgary, AB Canada
Posts: 45
Member Since: 06/12/02
posted May 25, 2004 2:49 AM

Okay thats understandable.

However if the called sub does not alter any objects and is used just for data manipulation and changes, would this call be safe from multiple threads?

for example from the conn.Execute() loop
Tony Priest



From: Utica, NY USA
Posts: 8466
Member Since: 04/11/00
posted May 25, 2004 7:30 AM

Yes. As long as all objects ar local to the Execute method.
computeronsite

From: Calgary, AB Canada
Posts: 45
Member Since: 06/12/02
posted May 28, 2004 3:12 AM

Would it be safe then to make changes to objects such as Listview, datagrid etc from within the Try loop inside the Connection event for the server?

I am assuming each connection event is a thread and therfore if an object is thread safe then changes to it would be safe inside this event as well.

Tony Priest



From: Utica, NY USA
Posts: 8466
Member Since: 04/11/00
posted May 28, 2004 9:07 AM

No. In the case of our server controls, the events are not threadsafe. If you have to access shared objects inside the event, you will have to do it like we do in the samples.
Reply | PowerTCP Sockets for .NET (Secure and Standard) Topics | Forums   
This site is powered by PowerTCP WebServer Tool PowerTCP WebServer for ActiveX