LifetimeServices LifetimeServices LifetimeServices LifetimeServices Class

定义

控制 .NET 远程处理生存期服务。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
继承
LifetimeServicesLifetimeServicesLifetimeServicesLifetimeServices
属性

示例

#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.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

<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
   
End Class 'Server

注解

分布式垃圾回收负责控制服务器应用程序的生存期, 并在其生存期过期时将其删除。Distributed garbage collection is responsible for controlling the lifetimes of server applications, and for deleting them when their lifetimes have expired. 传统上, 分布式垃圾回收使用引用计数和 ping 控制。Traditionally, distributed garbage collection uses reference counts and pinging for control. 如果每个对象有少量的客户端, 则这种方法很有效, 但当每个对象有数千个客户端时, 此功能就不能正常工作。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. 生存期服务可以假定传统分布式垃圾回收器的功能, 并且在客户端数量增加时可以很好地进行缩放。The lifetime service can assume the function of a traditional distributed garbage collector, and scales well when the number of clients increases.

生存期服务将租约与每个远程激活的对象相关联。The lifetime service associates a lease with each remotely activated object. 当租约过期时, 将删除该对象。When the lease expires, the object is removed.

备注

此类发出链接请求。This class makes a link demand. 如果直接调用方没有基础结构权限, 则会引发 SecurityException。A SecurityException is thrown if the immediate caller does not have infrastructure permission. 有关详细信息, 请参阅链接要求See Link Demands for more information.

构造函数

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

创建 LifetimeServices 的实例。Creates an instance of LifetimeServices.

属性

LeaseManagerPollTime LeaseManagerPollTime LeaseManagerPollTime LeaseManagerPollTime

获取或设置每次激活租约管理器以清除到期租约之间的时间间隔。Gets or sets the time interval between each activation of the lease manager to clean up expired leases.

LeaseTime LeaseTime LeaseTime LeaseTime

获取或设置 AppDomain 的初始租约时间范围。Gets or sets the initial lease time span for an AppDomain.

RenewOnCallTime RenewOnCallTime RenewOnCallTime RenewOnCallTime

获取或设置每当调用到达服务器对象时延续租约的时间。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

获取或设置租约管理器等待主办方返回租约续订时间的时间。Gets or sets the amount of time the lease manager waits for a sponsor to return with a lease renewal time.

方法

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

确定指定的对象是否等于当前对象。Determines whether the specified object is equal to the current object.

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

作为默认哈希函数。Serves as the default hash function.

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

获取当前实例的 TypeGets the Type of the current instance.

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

创建当前 Object 的浅表副本。Creates a shallow copy of the current Object.

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

返回表示当前对象的字符串。Returns a string that represents the current object.

(Inherited from Object)

安全性

SecurityPermission
用于处理基础结构代码。for operating with infrastructure code. 要求值: LinkDemand;权限值:InfrastructureDemand value: LinkDemand; Permission Value: Infrastructure

适用于