Hi everyone,
i have the following problem:
i got a host-gui which hosts a server-object with infinte lifetime. This
server creates 5 agent-objects (also marshal-by-ref) with a limited lifetime
of 10 sec and a RenewOnCallTime of 2 sec.
Unfortunately those agent-object are not disconnected as expected after 10
sec! The lifetime is even set back to 10 sec. all the time...
Furthermore the InitializeLifetimeService method is evidently not called
directly...if I call agent.GetLifetimeService() immediately after the
creation of an agent-object it returns null, what is not what one should
expect...
I hope someone could help me...Thanks for every mail!
Here is a code-snippet:
public class HostGUI : System.Windows.Forms.Form
{
public HostGUI()
{
InitializeComponent();
this.server =
(Services.Server)Activator.GetObject(typeof(Servic es.Server),
http://localhost:1234/Server.soap);
}
static void Main()
{
IDictionary props = new Hashtable();
props["typeFilterLevel"] = "Full";
SoapServerFormatterSinkProvider formatterProvider = new
SoapServerFormatterSinkProvider(props, null);
HttpServerChannel chnl;
chnl = new HttpServerChannel("ServerChannel", 1234,
formatterProvider);
ChannelServices.RegisterChannel(chnl);
RemotingConfiguration.RegisterWellKnownServiceType (typeof(Services.Server),
"Server.soap", WellKnownObjectMode.Singleton);
Application.Run(new HostGUI());
}
}
public class Server : MarshalByRefObject
{
public Server()
{
agents = new HybridDictionary();
agentSponsors = new HybridDictionary();
InitAgents();
}
public override object InitializeLifetimeService()
{
return null;
}
public void InitAgents()
{
Agent agent;
for(int i = 0; i < 5; i++)
{
agent = new Agent(i);
if(!agents.Contains(agent.Id))
agents.Add(agent.Id, agent);
ILease lease =
(ILease)RemotingServices.GetLifetimeService(agent) ;
if(lease != null)
{
//doSometing
}
else
{
//doSometingElse
}
}
}
}
public class Agent : MarshalByRefObject
{
public override object InitializeLifetimeService()
{
ILease tmp = (ILease)base.InitializeLifetimeService();
if(tmp.CurrentState.Equals(System.Runtime.Remoting .Lifetime.LeaseState.Initial))
{
tmp.InitialLeaseTime = TimeSpan.FromSeconds(10);
tmp.RenewOnCallTime = TimeSpan.FromSeconds(2);
}
return tmp;
}
}