Compartilhar via


Como: Substituir o método InitializeLifetimeService

This exemplo de código demonstrates a padrão Substituir the interface InitializeLifetimeService.

Exemplo

Public Class MyLifetimeControlObject
  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 'InitializeLifetimeService
End Class 'MyLifetimeControlObject
public class MyLifetimeControlObject: 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;
   }
}

Compilando o código

Este exemplo requer:

  • References to the Sistema. Runtime.Remoting.Lifetime namespace.

Consulte também

Conceitos

Inicializando concessões