class TestNet
{
TcpClient _client = null;
NetworkStream ns = null;
public TestNet()
{
_client = new TcpClient("127.0.0.1", int.Parse("7000"));
ns = _client.GetStream();
} ~TestNet()
{
string sendStr = "123456789";
byte[] data = System.Text.Encoding.UTF8.GetBytes (sendStr);
ns.Write(data ,0, data.Length);// 非托管资源已释放
}
}
{
TcpClient _client = null;
NetworkStream ns = null;
public TestNet()
{
_client = new TcpClient("127.0.0.1", int.Parse("7000"));
ns = _client.GetStream();
} ~TestNet()
{
string sendStr = "123456789";
byte[] data = System.Text.Encoding.UTF8.GetBytes (sendStr);
ns.Write(data ,0, data.Length);// 非托管资源已释放
}
}
试试把
TcpClient _client = null;
NetworkStream ns = null;
声明为静态的
~TestNet()
{
try
{
using (TcpClient tc = new TcpClient("127.0.0.1", int.Parse("7000")))
{
string sendStr = "123456789";
byte[] data = System.Text.Encoding.UTF8.GetBytes(sendStr);
tc.GetStream().Write(data, 0, data.Length);// 非托管资源已释放
}
}
catch (Exception)
{
}
}