all groups > dotnet distributed apps > december 2004 >
You're in the

dotnet distributed apps

group:

Need Help With InitializeLifetimeService Strategy


Need Help With InitializeLifetimeService Strategy localhost
12/22/2004 3:14:21 PM
dotnet distributed apps:


I have a remoted Singleton (Synchronized Hashtable) that is used by an
ASP.NET app. I would like it to recycle itself (so the RAM is
returned back to the runtime) if it has not been used for an hour (eg
during a maintenance window). Right now all I have in my class is:

// note - class inherits from MarshalByRefObject
public override Object InitializeLifetimeService()
{
return null;
}

I think I want some kind of timer that will make the instance
self-destruct, but the timer's countdown will reset on each usage.
But I canit find enough docs on InitializeLifetimeService and I don't
know if it's safe to use a Timer (which Timer?) for this object.

Help?

Thanks.
Re: Need Help With InitializeLifetimeService Strategy Sam Santiago
12/22/2004 10:53:27 PM
That's the whole purpose of this function. You should return an object that
implements the ILease interface with a time factor specified within it. The
Lease controls the lifetime of your object. If you check out the
documentation on this function it provides examples:

Public Overrides Function InitializeLifetimeService() As Object
Dim lease As ILease = CType(MyBase.InitializeLifetimeService(),
ILease)
If lease.CurrentState = LeaseState.Initial Then
lease.InitialLeaseTime = TimeSpan.FromMinutes(1)
lease.SponsorshipTimeout = TimeSpan.FromMinutes(2)
lease.RenewOnCallTime = TimeSpan.FromSeconds(2)
End If
Return lease
End Function

InitializeLifetimeService Method
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpref/html/frlrfsystemmarshalbyrefobjectclassinitializelifetimeservicetopic.asp

Managing the Lifetime of Remote .NET Objects with Leasing and Sponsorship
http://msdn.microsoft.com/msdnmag/issues/03/12/LeaseManager/default.aspx

Thanks,

Sam

--
_______________________________
Sam Santiago
ssantiago@n0spam-SoftiTechture.com
http://www.SoftiTechture.com
_______________________________
[quoted text, click to view]

AddThis Social Bookmark Button