I need an array of WithEvents Classes...

T

Terry Olsen

I want to have an array of class objects that raise an event when a
condition is true. Like so...
-------------------------------------------------------
Public Class ClientHandler

Public Event DataArrival(ByVal client As TcpClient)
Public Writer As BinaryWriter
Public Reader As BinaryReader
Private myClient As TcpClient

Public Sub New(ByVal client As TcpClient)
myClient = client
Dim Stream As NetworkStream = client.GetStream
Writer = New BinaryWriter(Stream)
Reader = New BinaryReader(Stream)
'Add code here to start a DataArrivalLoop Thread...
End Sub

Private Sub DataArrivalLoop()
Do
If Reader.PeekChar > 0 Then
RaiseEvent DataArrival(myClient)
End If
Loop
End Sub

End Class
--------------------------------------------------------------

Back in the main form code...

Dim WithEvents myClient(10) As ClientHandler '<--Gives an error that says
can't have an array of WithEvents variables.

I want to be able to have up to 10 clients connected and have a single event
handler like this:

Private Sub DataArrival(ByVal client As TcpClient) Handles
ClientHandler.DataArrival
'Do stuff to handle the event...
End Sub

Is this possible? How can I accomplish something like this?
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top