This documentation is archived and is not being maintained.

MarshalByRefObject.InitializeLifetimeService Method

Obtains a lifetime service object to control the lifetime policy for this instance.

[Visual Basic]
Public Overridable Function InitializeLifetimeService() As Object
public virtual object InitializeLifetimeService();
public: virtual Object* InitializeLifetimeService();
public function InitializeLifetimeService() : Object;

Return Value

An object of type ILease used to control the lifetime policy for this instance. This is the current lifetime service object for this instance if one exists; otherwise, a new lifetime service object initialized to the value of the LifetimeServices.LeaseManagerPollTime property.


Exception Type Condition
SecurityException The immediate caller does not have infrastructure permission.


For more information about lifetime services, see the LifetimeServices class.


[Visual Basic, C#, C++] The following code example demonstrates creating a lease.

[Visual Basic] 
Public Class LSClass
    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

    Public Shared Sub Main()  
    ' The main thread processing is here.
    End Sub
End Class

public class MyClass : 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;

public __gc class MyClass : public MarshalByRefObject
  Object* InitializeLifetimeService()
    ILease* lease = dynamic_cast<ILease*>(MarshalByRefObject::InitializeLifetimeService());
    if (lease->CurrentState == LeaseState::Initial)
         lease->InitialLeaseTime = TimeSpan::FromMinutes(1);
         lease->SponsorshipTimeout = TimeSpan::FromMinutes(2);
         lease->RenewOnCallTime = TimeSpan::FromSeconds(2);
    return lease;

[JScript] No example is available for JScript. To view a Visual Basic, C#, or C++ example, click the Language Filter button Language Filter in the upper-left corner of the page.


Platforms: Windows 98, Windows NT 4.0, Windows Millennium Edition, Windows 2000, Windows XP Home Edition, Windows XP Professional, Windows Server 2003 family

.NET Framework Security: 

See Also

MarshalByRefObject Class | MarshalByRefObject Members | System Namespace