Jump to content
Xtreme .Net Talk

Recommended Posts

Posted

Hey all, I'm currently writing a VB.NET DLL to handle TCP sockets in the same way as the old VB6 WinSock control, to simplify it for myself. However, I've run into this error:

 

"Access of shared member, constant member, enum member or nested type through an instance; qualifying expression will not be evaluated"

 

The key code is below (a snippet from the class), and I've highlighted the line that causes the error.

 



Public Event DataArrival(ByVal bytesTotal As Long)


Private sck As System.Net.Sockets.TcpClient
Private stream As System.Net.Sockets.NetworkStream
Private newThread As System.Threading.Thread

Public Sub New()
sck = New System.Net.Sockets.TcpClient()
stream = sck.GetStream

newThread = New System.Threading.Thread(AddressOf listenSub)
newThread.Priority = Threading.ThreadPriority.Normal
newThread.Start()
End Sub

Private Sub listenSub()
Do
[color=Red]newThread.Sleep(200)[/color]'This is the problem!
If stream.Length <> 0 Then
RaiseEvent DataArrival(stream.Length)
End If
Loop

End Sub
[/Code]

 

Now what that line is supposed to achieve is to pause the listening loop whilst checking for data being sent to the socket to avoid CPU burn. How do I fix this error, or is there a better way to implement this loop?

Chaos is merely logic beyond human comprehension
Posted
System.Threading.Thread.Sleep(200)

should do the trick

 

Cheers Damp, I'll give it a try right away!

Chaos is merely logic beyond human comprehension

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...