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 InitializeLifet imeService method is evidently not called
directly...if I call agent.GetLifeti meService() 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()
{
InitializeCompo nent();
this.server =
(Services.Serve r)Activator.Get Object(typeof(S ervices.Server) ,
http://localhost:1234/Server.soap);
}
static void Main()
{
IDictionary props = new Hashtable();
props["typeFilterLeve l"] = "Full";
SoapServerForma tterSinkProvide r formatterProvid er = new
SoapServerForma tterSinkProvide r(props, null);
HttpServerChann el chnl;
chnl = new HttpServerChann el("ServerChann el", 1234,
formatterProvid er);
ChannelServices .RegisterChanne l(chnl);
RemotingConfigu ration.Register WellKnownServic eType(typeof(Se rvices.Server),
"Server.soa p", WellKnownObject Mode.Singleton) ;
Application.Run (new HostGUI());
}
}
public class Server : MarshalByRefObj ect
{
public Server()
{
agents = new HybridDictionar y();
agentSponsors = new HybridDictionar y();
InitAgents();
}
public override object InitializeLifet imeService()
{
return null;
}
public void InitAgents()
{
Agent agent;
for(int i = 0; i < 5; i++)
{
agent = new Agent(i);
if(!agents.Cont ains(agent.Id))
agents.Add(agen t.Id, agent);
ILease lease =
(ILease)Remotin gServices.GetLi fetimeService(a gent);
if(lease != null)
{
//doSometing
}
else
{
//doSometingElse
}
}
}
}
public class Agent : MarshalByRefObj ect
{
public override object InitializeLifet imeService()
{
ILease tmp = (ILease)base.In itializeLifetim eService();
if(tmp.CurrentS tate.Equals(Sys tem.Runtime.Rem oting.Lifetime. LeaseState.Init ial))
{
tmp.InitialLeas eTime = TimeSpan.FromSe conds(10);
tmp.RenewOnCall Time = TimeSpan.FromSe conds(2);
}
return tmp;
}
}