« Onion Horoscope Feeds | Main | Visual C# 2005 Express Edition Beta »
August 15, 2004
Lifetime ILease and InitializeLifetimeService()
When creating a remotable class or handler, your object should most likely have a lifetime lease, unless it is desirable that it should be short-lived. The default lease time for ILease is set to 5 minutes. After that the lease expires and object becomes garbage collector food. The code below is an example of creating a lifetime lease for the class Example.cs.
using System;
using System.Runtime.Remoting.Lifetime;
namespace Remotable.Services
{
///
/// By Default an object lease is provided for 5 minutes. You
/// should create a lifetime ILease, otherwise the garbabge collector
/// will destroy your instantiated class
///
public class Example : MarshalByRefObject
{
public override Object InitializeLifetimeService()
{
ILease lease = (ILease)base.InitializeLifetimeService();
if (lease.CurrentState == LeaseState.Initial)
{
lease.SponsorshipTimeout = TimeSpan.FromSeconds(0);
lease.InitialLeaseTime = TimeSpan.FromSeconds(0);
}
return lease;
}
}
}
Posted by 0xFF3300 at August 15, 2004 11:53 AM
Trackback Pings
TrackBack URL for this entry:
http://www.dudeforce.net/cgi-bin/mt-tb.cgi/92
Listed below are links to weblogs that reference Lifetime ILease and InitializeLifetimeService():
Comments
Post a comment
Thanks for signing in, . Now you can comment. (sign out)
(If you haven't left a comment here before, you may need to be approved by the site owner before your comment will appear. Until then, it won't appear on the entry. Thanks for waiting.)