MarshalByRefObject.InitializeLifetimeService MarshalByRefObject.InitializeLifetimeService MarshalByRefObject.InitializeLifetimeService MarshalByRefObject.InitializeLifetimeService Method

Definición

Obtiene un objeto de servicio de duración para controlar la directiva de duración de esta instancia.Obtains a lifetime service object to control the lifetime policy for this instance.

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

Devoluciones

Objeto de tipo ILease utilizado para controlar la directiva de duración de esta instancia.An object of type ILease used to control the lifetime policy for this instance. Éste es el objeto de servicio de duración actual de esta instancia si existe una; en caso contrario, un nuevo objeto de servicio de duración inicializado en el valor de la propiedad 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.

Excepciones

El llamador inmediato no tiene permisos de infraestructura.The immediate caller does not have infrastructure permission.

Ejemplos

En el ejemplo de código siguiente se muestra cómo crear una concesión.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

Comentarios

Para obtener más información acerca de los servicios de duración, vea el LifetimeServices clase.For more information about lifetime services, see the LifetimeServices class.

Seguridad

SecurityCriticalAttribute
requiere plena confianza para el llamador inmediato.requires full trust for the immediate caller. Este miembro no se puede usar código de confianza parcial o transparente.This member cannot be used by partially trusted or transparent code.

Se aplica a