By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
457,695 Members | 1,207 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 457,695 IT Pros & Developers. It's quick & easy.

Valid object reference ?

P: n/a
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
......


Nov 21 '05 #1
Share this Question
Share on Google+
2 Replies


P: n/a
Friskussen,

The answer is simple, an object lives in dotNet as long as that there is a
reference to it.

I hope this helps?

Cor

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
.....

Nov 21 '05 #2

P: n/a

But is it still a reference to the object in this case ?

Or, to put it another way:

Does the thread keep a reference to the object ?

In that case, of course, my question is perfectly answered )

Nice weekend !

"Cor Ligthert" <no**********@planet.nl> wrote in message
news:#K**************@TK2MSFTNGP10.phx.gbl...
Friskussen,

The answer is simple, an object lives in dotNet as long as that there is a
reference to it.

I hope this helps?

Cor

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
.....


Nov 21 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.