F
Friskusen
Hello VB.net programmers !
I'm just trying to understand what happens with an object which is
initialised
over and over again.
The code fragment below illustrates my problem. This code is simply a tcp
listener
which creates a new client object and starts a new thread inside that
object to
handle an incoming request.
But what happens when a new connection request arrives and 'the same'
client object
is initialized again ? I imagine that the 'old object' survives a clean up
as long as a thread still may be running with a reference to that object...
Running the code indicates that this is so, but i'm not sure....yet
Comments are welcome,
Thanks,
Frode
.....
Public Sub CheckQueue()
'============================================================
' Any clients knocking on my door ?
'
If MySocket.Poll(1000, SelectMode.SelectRead) Then
Select Case TcpService.ToUpper
Case "POP"
'Initialize a new PopClient..
Dim MyPop As New Pop3Client(MySocket.Accept, Idx)
'..and start a new thread to handle this client...
Dim MyThread As New Thread(AddressOf MyPop.NewClient)
MyThread.Start()
Case "SMTP"
Dim MySmtp As New SmtpClient(MySocket.Accept, Idx)
Dim MyThread As New Thread(AddressOf MySmtp.NewClient)
MyThread.Start()
End Select
ClientCount += 1
RaiseEvent StatusChanged(Idx)
End If
End Sub
......
I'm just trying to understand what happens with an object which is
initialised
over and over again.
The code fragment below illustrates my problem. This code is simply a tcp
listener
which creates a new client object and starts a new thread inside that
object to
handle an incoming request.
But what happens when a new connection request arrives and 'the same'
client object
is initialized again ? I imagine that the 'old object' survives a clean up
as long as a thread still may be running with a reference to that object...
Running the code indicates that this is so, but i'm not sure....yet
Comments are welcome,
Thanks,
Frode
.....
Public Sub CheckQueue()
'============================================================
' Any clients knocking on my door ?
'
If MySocket.Poll(1000, SelectMode.SelectRead) Then
Select Case TcpService.ToUpper
Case "POP"
'Initialize a new PopClient..
Dim MyPop As New Pop3Client(MySocket.Accept, Idx)
'..and start a new thread to handle this client...
Dim MyThread As New Thread(AddressOf MyPop.NewClient)
MyThread.Start()
Case "SMTP"
Dim MySmtp As New SmtpClient(MySocket.Accept, Idx)
Dim MyThread As New Thread(AddressOf MySmtp.NewClient)
MyThread.Start()
End Select
ClientCount += 1
RaiseEvent StatusChanged(Idx)
End If
End Sub
......