Obtains a lifetime service object to control the lifetime policy for this instance.
[Visual Basic] Public Overridable Function InitializeLifetimeService() As Object [C#] public virtual object InitializeLifetimeService(); [C++] public: virtual Object* InitializeLifetimeService(); [JScript] public function InitializeLifetimeService() : Object;
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#] 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 [C#] 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; } }
[C++, JScript] No example is available for C++ or JScript. To view a Visual Basic or C# example, click the Language Filter button
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:
MarshalByRefObject Class | MarshalByRefObject Members | System Namespace