NET Remoting problem
Hi, here some code:
----------------------------------------------------------------------------
// remoting server
using System;
using System.Runtime.Remoting;
using System.Runtime.Remoting.Channels;
using System.Runtime.Remoting.Channels.Tcp;
namespace Test
{
public class Server
{
private static int mPort = 60000;
public static void Main(string[] args)
{
try
{
ChannelServices.RegisterChannel(new TcpChannel(mPort), true);
RemotingConfiguration.RegisterActivatedServiceType (typeof(BusinessTier));
Console.WriteLine("Server started on port " + mPort);
}
catch (Exception e)
{
Console.WriteLine(e);
}
Console.WriteLine("Press enter to exit...");
Console.ReadLine();
}
}
}
----------------------------------------------------------------------------
// client activated object
using System;
using System.Collections;
using System.IO;
using System.Runtime.Remoting;
namespace Test
{
public class BusinessTier : MarshalByRefObject
{
public BusinessTier()
{
}
public bool Connect(string user, string pass)
{
// connect to database
}
private void Dispose(bool disposing)
{
// close connection
}
public void Dispose()
{
Dispose(true);
GC.SuppressFinalize(this);
}
~BusinessTier()
{
Dispose(false);
}
}
}
----------------------------------------------------------------------------
// client application
...
ChannelServices.RegisterChannel(new TcpChannel(), true);
RemotingConfiguration.RegisterActivatedClientType(
new ActivatedClientTypeEntry(typeof(BusinessTier), SERVER));
mBsTier = new BusinessTier();
mBsTier.Connect(user, pass);
...
----------------------------------------------------------------------------
Problem:
Why server don't call BusinessTier.Dispose() when it stopped or client disconnected by timeout?
|