public class RequestStream
{
private TcpClient socket;
private NetworkStream stream;
private String address;
private String port;
public RequestStream(String aAddress, String aPort)
{
address = aAddress;
port = aPort;
try
{
socket = new TcpClient();
socket.Connect(address, int.Parse(port));
stream = socket.GetStream();
}
catch (Exception ex)
{
//
}
}
I have a separate thread that "heartbeats" the servers to check their status. When I need to change servers I trigger the following code situated on the DataStore object.public void resetAllThreads()
{
try
{
lock (_locker)
{
requestStream = new RequestStream(jeqiReference.GetAddress(), jeqiReference.GetPort());
}
}
catch (Exception ex)
{
//
}
}
A breakpoint shows this is working correctly.requestStream = new RequestStream(jeqiReference.GetAddress(), jeqiReference.GetPort());
raceDay = new RaceDay(jeqiReference, ref requestStream);
ASKER
On the Raceday object the adress stays the same but the stream is null.since you created a new RequestStream and a new Raceday object, the old RequestStream and old Raceday object are no longer valid and are subject of the garbage collector (gc). that means the Raceday objetc you were looking for is no longer the one which should be alive but needs to be replaced by the new one.
raceDay = new RaceDay(jeqiReference, ref requestStream);
should release and clear old raceDay object.ASKER
ASKER
The .NET Framework is not specific to any one programming language; rather, it includes a library of functions that allows developers to rapidly build applications. Several supported languages include C#, VB.NET, C++ or ASP.NET.
TRUSTED BY
Open in new window
When you are passing the object by value, the value is a reference for reference types - a way of getting to the object (a pointer to memory location). The RaceDay class will not be able to change the stream object but only its public properties or whatever state is changed by public methods.