LifetimeServices LifetimeServices LifetimeServices LifetimeServices Class

Definición

Controla los servicios de duración de .NET Remoting.Controls the.NET remoting lifetime services.

public ref class LifetimeServices sealed
[System.Runtime.InteropServices.ComVisible(true)]
[System.Security.SecurityCritical]
public sealed class LifetimeServices
type LifetimeServices = class
Public NotInheritable Class LifetimeServices
Herencia
LifetimeServicesLifetimeServicesLifetimeServicesLifetimeServices
Atributos

Ejemplos

#using <system.dll>
#using <system.runtime.remoting.dll>
#using "service.dll"

using namespace System;
using namespace System::Runtime::Remoting;
using namespace System::Runtime::Remoting::Channels;
using namespace System::Runtime::Remoting::Channels::Http;
using namespace System::Runtime::Remoting::Lifetime;

int main()
{
   LifetimeServices::LeaseTime = TimeSpan::FromSeconds( 5 );
   LifetimeServices::LeaseManagerPollTime = TimeSpan::FromSeconds( 3 );
   LifetimeServices::RenewOnCallTime = TimeSpan::FromSeconds( 2 );
   LifetimeServices::SponsorshipTimeout = TimeSpan::FromSeconds( 1 );
   ChannelServices::RegisterChannel( gcnew HttpChannel( 8080 ) );
   RemotingConfiguration::RegisterActivatedServiceType( ClientActivatedType::typeid );
   Console::WriteLine( "The server is listening. Press Enter to exit...." );
   Console::ReadLine();
   Console::WriteLine( "GC'ing." );
   GC::Collect();
   GC::WaitForPendingFinalizers();
   return 0;
}
using System;
using System.Runtime.Remoting;
using System.Runtime.Remoting.Channels;
using System.Runtime.Remoting.Channels.Http;
using System.Runtime.Remoting.Lifetime;
using System.Security.Permissions;

public class Server {

   public static void Main() {

      Server myServer = new Server();
      myServer.Run();
   }
 
[SecurityPermission(SecurityAction.Demand, Flags = SecurityPermissionFlag.Infrastructure)]
   public void Run()
   {
      LifetimeServices.LeaseTime = TimeSpan.FromSeconds(5);
      LifetimeServices.LeaseManagerPollTime = TimeSpan.FromSeconds(3);
      LifetimeServices.RenewOnCallTime = TimeSpan.FromSeconds(2);
      LifetimeServices.SponsorshipTimeout = TimeSpan.FromSeconds(1);
   
      ChannelServices.RegisterChannel(new HttpChannel(8080), true);
      RemotingConfiguration.RegisterActivatedServiceType(typeof(ClientActivatedType));
      
      Console.WriteLine("The server is listening. Press Enter to exit....");
      Console.ReadLine();  

      Console.WriteLine("GC'ing.");
      GC.Collect();
      GC.WaitForPendingFinalizers();
   }
}
Imports System
Imports System.Runtime.Remoting
Imports System.Runtime.Remoting.Channels
Imports System.Runtime.Remoting.Channels.Http
Imports System.Runtime.Remoting.Lifetime
Imports System.Security.Permissions


Public Class Server
   
   Public Shared Sub Main()
      Dim myServer As New Server()
      myServer.Run()
   End Sub 'Main

<SecurityPermission(SecurityAction.Demand, Flags:=SecurityPermissionFlag.Infrastructure)> _ 
   Public Sub Run()
      LifetimeServices.LeaseTime = TimeSpan.FromSeconds(5)
      LifetimeServices.LeaseManagerPollTime = TimeSpan.FromSeconds(3)
      LifetimeServices.RenewOnCallTime = TimeSpan.FromSeconds(2)
      LifetimeServices.SponsorshipTimeout = TimeSpan.FromSeconds(1)
      
      
      ChannelServices.RegisterChannel(New HttpChannel(8080), True)
      RemotingConfiguration.RegisterActivatedServiceType(GetType(ClientActivatedType))
      
      Console.WriteLine("The server is listening. Press Enter to exit....")
      Console.ReadLine()
      
      Console.WriteLine("GC'ing.")
      GC.Collect()
      GC.WaitForPendingFinalizers()
   End Sub 'Run
   
End Class 'Server

Comentarios

Colección de elementos no utilizados distribuida es responsable de controlar las duraciones de las aplicaciones de servidor y para eliminarlos cuando expira el período de duración.Distributed garbage collection is responsible for controlling the lifetimes of server applications, and for deleting them when their lifetimes have expired. Tradicionalmente, colección de elementos no utilizados distribuida utiliza recuentos de referencias y hacer ping para el control.Traditionally, distributed garbage collection uses reference counts and pinging for control. Esto funciona bien cuando hay pocos clientes por objeto, pero no funciona bien cuando hay miles de clientes por cada objeto.This works well when there are a few clients per object, but does not work well when there are thousands of clients per each object. El servicio de duración puede asumir la función de un recolector de elementos no utilizados distribuido tradicional y se escala bien cuando aumenta el número de clientes.The lifetime service can assume the function of a traditional distributed garbage collector, and scales well when the number of clients increases.

El servicio de duración asocia una concesión con cada objeto activado de forma remota.The lifetime service associates a lease with each remotely activated object. Cuando expira la concesión, se quita el objeto.When the lease expires, the object is removed.

Nota

Esta clase realiza una petición de vínculo.This class makes a link demand. Si el llamador inmediato no tiene permiso de infraestructura, se produce una excepción SecurityException.A SecurityException is thrown if the immediate caller does not have infrastructure permission. Consulte peticiones de vínculo para obtener más información.See Link Demands for more information.

Constructores

LifetimeServices() LifetimeServices() LifetimeServices() LifetimeServices()

Crea una instancia de LifetimeServices.Creates an instance of LifetimeServices.

Propiedades

LeaseManagerPollTime LeaseManagerPollTime LeaseManagerPollTime LeaseManagerPollTime

Obtiene o establece el intervalo de tiempo entre cada activación del administrador de concesiones para limpiar las concesiones expiradas.Gets or sets the time interval between each activation of the lease manager to clean up expired leases.

LeaseTime LeaseTime LeaseTime LeaseTime

Obtiene o establece el intervalo de tiempo de concesión inicial de un AppDomain.Gets or sets the initial lease time span for an AppDomain.

RenewOnCallTime RenewOnCallTime RenewOnCallTime RenewOnCallTime

Obtiene o establece el tiempo en que se amplía la concesión cada que vez que se recibe una llamada en el objeto de servidor.Gets or sets the amount of time by which the lease is extended every time a call comes in on the server object.

SponsorshipTimeout SponsorshipTimeout SponsorshipTimeout SponsorshipTimeout

Obtiene o establece el tiempo que el administrador de concesiones espera a que el patrocinador vuelva con un tiempo de renovación de concesión.Gets or sets the amount of time the lease manager waits for a sponsor to return with a lease renewal time.

Métodos

Equals(Object) Equals(Object) Equals(Object) Equals(Object)

Determina si el objeto especificado es igual al objeto actual.Determines whether the specified object is equal to the current object.

(Inherited from Object)
GetHashCode() GetHashCode() GetHashCode() GetHashCode()

Sirve como la función hash predeterminada.Serves as the default hash function.

(Inherited from Object)
GetType() GetType() GetType() GetType()

Obtiene el Type de la instancia actual.Gets the Type of the current instance.

(Inherited from Object)
MemberwiseClone() MemberwiseClone() MemberwiseClone() MemberwiseClone()

Crea una copia superficial del objeto Object actual.Creates a shallow copy of the current Object.

(Inherited from Object)
ToString() ToString() ToString() ToString()

Devuelve una cadena que representa el objeto actual.Returns a string that represents the current object.

(Inherited from Object)

Seguridad

SecurityPermission
para trabajar con código de infraestructura.for operating with infrastructure code. Valor de petición: LinkDemand; Valor de permiso: InfrastructureDemand value: LinkDemand; Permission Value: Infrastructure

Se aplica a