Export (0) Print
Expand All
This topic has not yet been rated - Rate this topic

MarshalByRefObject.InitializeLifetimeService Method

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;

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.

Exceptions

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

Remarks

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

Example

[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


[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++] 
public __gc class MyClass : public MarshalByRefObject
{
public:
  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.

Requirements

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

Show:
© 2014 Microsoft. All rights reserved.