MarshalByRefObject.InitializeLifetimeService 메서드

정의

주의

This Remoting API is not supported and throws PlatformNotSupportedException.

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

public:
 virtual System::Object ^ InitializeLifetimeService();
[System.Obsolete("This Remoting API is not supported and throws PlatformNotSupportedException.", DiagnosticId="SYSLIB0010", UrlFormat="https://aka.ms/dotnet-warnings/{0}")]
public virtual object InitializeLifetimeService ();
public virtual object InitializeLifetimeService ();
[System.Security.SecurityCritical]
public virtual object InitializeLifetimeService ();
[<System.Obsolete("This Remoting API is not supported and throws PlatformNotSupportedException.", DiagnosticId="SYSLIB0010", UrlFormat="https://aka.ms/dotnet-warnings/{0}")>]
abstract member InitializeLifetimeService : unit -> obj
override this.InitializeLifetimeService : unit -> obj
abstract member InitializeLifetimeService : unit -> obj
override this.InitializeLifetimeService : unit -> obj
[<System.Security.SecurityCritical>]
abstract member InitializeLifetimeService : unit -> obj
override this.InitializeLifetimeService : unit -> obj
Public Overridable Function InitializeLifetimeService () As Object

반환

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.

.NET Core 및 .NET 5+ 전용: 모든 경우.NET Core and .NET 5+ only: In all cases.

예제

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

public ref class MyClass: public MarshalByRefObject
{
public:
   
   [System::Security::Permissions::SecurityPermissionAttribute
   (System::Security::Permissions::SecurityAction::Demand,
   Flags=System::Security::Permissions::SecurityPermissionFlag::Infrastructure)]
   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
{
  [SecurityPermissionAttribute(SecurityAction.Demand,
                               Flags=SecurityPermissionFlag.Infrastructure)]
  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

설명

이 메서드는 .NET 5.0부터 사용 되지 않는 것으로 표시 되었습니다.This method is marked obsolete starting in .NET 5.0.

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

적용 대상