In a client app where you want to extend the lease of a remote object you would typically obtain an ILease interface for the object by calling
ILease lease = (ILease)RemotingServices.GetLifetimeService( remoteObject );
and then pass it your custom sponsor object
lease.Register( customSponsor );
where your custom sponsor class will look something like this:
private class CustomSponsor : MarshalByRefObject, ISponsor
{
public TimeSpan Renewal(ILease lease)
{
Debug.Assert(lease.CurrentState == LeaseState.Active);
//Renew lease by 5 minutes
return TimeSpan.FromMinutes(5);
}
}
For more information check out this helpful MSDN article on leasing and sponsorship.
http://msdn.microsoft.com/en-us/magazine/cc300474.aspx
The link no longer works - it was in the December 2003 issue though which can be downloaded in CHM format from the same page.
A wayback machine link is here:
https://web.archive.org/web/20080906214332/http://msdn.microsoft.com/en-us/magazine/cc300474.aspx
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…