MarshalByRefObject.InitializeLifetimeService Method


이 인스턴스의 수명 정책을 제어하는 수명 서비스 개체를 가져옵니다.Obtains a lifetime service object to control the lifetime policy for this instance.

 virtual System::Object ^ InitializeLifetimeService();
public virtual object InitializeLifetimeService ();
public virtual object InitializeLifetimeService ();
abstract member InitializeLifetimeService : unit -> obj
override this.InitializeLifetimeService : unit -> obj
Public Overridable Function InitializeLifetimeService () As Object



ILease 형식의 개체는 이 인스턴스의 수명 정책을 제어하는 데 사용됩니다.An object of type ILease used to control the lifetime policy for this instance. 이 개체는 해당 인스턴스에 대한 현재 수명 서비스 개체이고(있는 경우), 그렇지 않으면 LeaseManagerPollTime 속성의 값으로 초기화된 새 수명 서비스 개체입니다.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 LeaseManagerPollTime property.



직접 실행 호출자에 인프라 권한이 없는 경우The immediate caller does not have infrastructure permission.


다음 코드 예제에서는 임대를 작성 하는 방법을 보여 줍니다.The following code example demonstrates creating a lease.

public ref class MyClass: public MarshalByRefObject
   virtual Object^ InitializeLifetimeService() override
      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;


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 Class LSClass
    Inherits MarshalByRefObject
    <SecurityPermissionAttribute(SecurityAction.Demand, _
                                 Flags:=SecurityPermissionFlag.Infrastructure)> _
    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


수명 서비스에 대 한 자세한 내용은 LifetimeServices 클래스를 참조 하세요.For more information about lifetime services, see the LifetimeServices class.

Applies to