Compartilhar via


MarshalByRefObject.InitializeLifetimeService Método

Definição

Cuidado

This Remoting API is not supported and throws PlatformNotSupportedException.

Obtém um objeto de serviço de tempo de vida para controlar a política de tempo de vida para essa instância.

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

Retornos

Object

Um objeto do tipo ILease usado para controlar a política de tempo de vida para esta instância. Esse é o objeto de serviço de tempo de vida atual para essa instância se existir alguma; caso contrário, um novo objeto de serviço de tempo de vida inicializado para o valor da propriedade LeaseManagerPollTime.

Atributos

Exceções

O chamador imediato não tem permissão de infraestrutura.

Somente .NET Core e .NET 5+: Em todos os casos.

Exemplos

O exemplo de código a seguir demonstra a criação de uma concessão.

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

Comentários

Esse método é marcado como obsoleto a partir do .NET 5.

Para obter mais informações sobre serviços de tempo de vida, consulte a LifetimeServices classe .

Aplica-se a