LifetimeServices 类
控制 .NET 远程处理生存期服务。
**命名空间:**System.Runtime.Remoting.Lifetime
**程序集:**mscorlib(在 mscorlib.dll 中)
语法
声明
<ComVisibleAttribute(True)> _
Public NotInheritable Class LifetimeServices
用法
Dim instance As LifetimeServices
[ComVisibleAttribute(true)]
public sealed class LifetimeServices
[ComVisibleAttribute(true)]
public ref class LifetimeServices sealed
/** @attribute ComVisibleAttribute(true) */
public final class LifetimeServices
ComVisibleAttribute(true)
public final class LifetimeServices
备注
分布式垃圾回收负责控制服务器应用程序的生存期,并负责在它们的生存期结束时删除它们。传统上,分布式垃圾回收使用引用计数和 Ping 进行控制。这在每个对象有少数几个客户端时可以很好地工作,但在每个对象有数千个客户端时效率很低。生存期服务可采用传统分布式垃圾回收器的功能,并在客户端数目增加时能很好地扩展。
生存期服务将租约与每个远程激活的对象关联。当租约过期时,对象将被移除。
提示
此类生成链接要求。如果直接调用方没有基础结构权限,则会引发 SecurityException。有关更多信息,请参见 链接要求。
示例
Imports System
Imports System.Runtime.Remoting
Imports System.Runtime.Remoting.Channels
Imports System.Runtime.Remoting.Channels.Http
Imports System.Runtime.Remoting.Lifetime
Public Class Server
Public Shared Sub Main()
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))
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 'Main
End Class 'Server
using System;
using System.Runtime.Remoting;
using System.Runtime.Remoting.Channels;
using System.Runtime.Remoting.Channels.Http;
using System.Runtime.Remoting.Lifetime;
public class Server {
public static void Main() {
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));
RemotingConfiguration.RegisterActivatedServiceType(typeof(ClientActivatedType));
Console.WriteLine("The server is listening. Press Enter to exit....");
Console.ReadLine();
Console.WriteLine("GC'ing.");
GC.Collect();
GC.WaitForPendingFinalizers();
}
}
#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;
}
.NET Framework 安全性
- SecurityPermission 用于操作基础结构代码。要求值:SecurityAction.LinkDemand;权限值:SecurityPermissionFlag.Infrastructure
继承层次结构
System.Object
System.Runtime.Remoting.Lifetime.LifetimeServices
线程安全
此类型的任何公共静态(Visual Basic 中的 Shared)成员都是线程安全的,但不保证所有实例成员都是线程安全的。
平台
Windows 98、Windows 2000 SP4、Windows Millennium Edition、Windows Server 2003、Windows XP Media Center Edition、Windows XP Professional x64 Edition、Windows XP SP2、Windows XP Starter Edition
.NET Framework 并不是对每个平台的所有版本都提供支持。有关受支持版本的列表,请参见系统要求。
版本信息
.NET Framework
受以下版本支持:2.0、1.1、1.0