NGWS SDK Documentation  

This is preliminary documentation and subject to change.
To comment on this topic, please send us email at ngwssdk@microsoft.com. Thanks!

Lease.InitializeLifetimeService

[Visual Basic]
Overrides Public Function InitializeLifetimeService() As Object
[C#]
public override object InitializeLifetimeService();
[C++]
public: override Object* InitializeLifetimeService();
[JScript]
public override function InitializeLifetimeService() : Object;

Return Value

Example [C#]

[C#]

public class Foo : MarshalByRefObject
{
  public override Object InitializeLifetimeService()
  {
    ILease lease = (ILease)base.InitializeLifetimeService();
    if (lease.CurrentState == LeaseState.Initial)
    {
         lease.InitialLeaseTime = TimeSpan.FromMinutes(1);
         lease.SponsorshipTimeout = TimeSpan.FromMinutes(2);
          lease.RenewOnCallTime = TimeSpan.FromSeconds(2);
    }
      return lease;
  }
}

Property sets will only work when a lease is in the initial state. A lease is in the initial state which it is created by InitializeLifetimeService. It is placed in the Active state when the object is marshaled.

When theILease lease = (ILease)base.InitializeLifetimeService(); is called within InitializeLifetimeService, either an existing lease is returned for this object, or if no lease exists, a new lease is returned. Only if a new lease is returned can the lease properties be set. An exception will occur if an attempt is made to set an existing lease. A new lease has the state LeaseState.Initial, an existing lease has the state LeaseState.Active or LeaseState.Expired.

The only call that counts for the Lifetime service is the call to InitializeLifetimeService from the Remoting Lifetime Lease infrastructure (implemented as an AppDomain property), this the call that acivates the lease. Someone else can call InitializeLifetimeService and create a lease, but that lease will stay in its initial state until it is returned to the Remoting Lease Infrastructure. An existing lease that is not in the initial state cannot be set with new values, although it can be returned to Remoting Lifetime Lease infrastructure for use use by the new sink for RenewOnCall when an invocation on the object occurs. This allows multiple sinks for an object to point to the same lease.

No lease will be created if the leasetime is zero or a null lease is returned lease.InitialLeaseTime = TimeSpan.Zero; or return null. No sink will be created if the RenewOnCallTime is Zero, but a lease will be created. lease.RenewOnCallTime = TimeSpan.Zero;

See Also

Lease Class | Lease Members | System.Runtime.Remoting Namespace