Share via


How to: Override the InitializeLifetimeService Interface

This topic is specific to a legacy technology that is retained for backward compatibility with existing applications and is not recommended for new development. Distributed applications should now be developed using the  Windows Communication Foundation (WCF).

This code example demonstrates a standard override the InitializeLifetimeService interface.

Example

Public Class MyLifetimeControlObject
  Inherits MarshalByRefObject
  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
End Class 'MyLifetimeControlObject
public class MyLifetimeControlObject: 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;
   }
}

Compiling the Code

This example requires:

  • References to the System.Runtime.Remoting.Lifetime namespace.

See Also

Concepts

Initializing Leases