LifetimeServices 类
定义
重要
一些信息与预发行产品相关,相应产品在发行之前可能会进行重大修改。 对于此处提供的信息,Microsoft 不作任何明示或暗示的担保。
控制.NET远程处理生存期服务。
public ref class LifetimeServices sealed
public sealed class LifetimeServices
[System.Runtime.InteropServices.ComVisible(true)]
public sealed class LifetimeServices
[System.Runtime.InteropServices.ComVisible(true)]
[System.Security.SecurityCritical]
public sealed class LifetimeServices
type LifetimeServices = class
[<System.Runtime.InteropServices.ComVisible(true)>]
type LifetimeServices = class
[<System.Runtime.InteropServices.ComVisible(true)>]
[<System.Security.SecurityCritical>]
type LifetimeServices = class
Public NotInheritable Class LifetimeServices
- 继承
-
LifetimeServices
- 属性
示例
#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;
public class Server {
public static void Main() {
Server myServer = new Server();
myServer.Run();
}
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
注解
分布式垃圾回收负责控制服务器应用程序的生存期,并在其生存期过期时将其删除。 传统上,分布式垃圾回收使用引用计数和 ping 进行控制。 当每个对象有几个客户端,但每个对象有数千个客户端时,这很有效。 生存期服务可以假设传统分布式垃圾回收器的功能,并在客户端数量增加时很好地缩放。
生存期服务将租约与每个远程激活的对象相关联。 租约到期后,将删除该对象。
注释
此类需要链接。 如果即时调用方没有基础结构权限,则会引发 SecurityException。
构造函数
| 名称 | 说明 |
|---|---|
| LifetimeServices() |
已过时.
创建 LifetimeServices 的实例。 |
属性
| 名称 | 说明 |
|---|---|
| LeaseManagerPollTime |
获取或设置每次激活租约管理器以清理过期租约之间的时间间隔。 |
| LeaseTime |
获取或设置一个 AppDomain初始租约时间跨度。 |
| RenewOnCallTime |
获取或设置每次调用在服务器对象上时扩展租约的时间量。 |
| SponsorshipTimeout |
获取或设置租约管理器等待发起人返回的租约续订时间的时间。 |
方法
| 名称 | 说明 |
|---|---|
| Equals(Object) |
确定指定的对象是否等于当前对象。 (继承自 Object) |
| GetHashCode() |
用作默认哈希函数。 (继承自 Object) |
| GetType() |
获取当前实例的 Type。 (继承自 Object) |
| MemberwiseClone() |
创建当前 Object的浅表副本。 (继承自 Object) |
| ToString() |
返回一个表示当前对象的字符串。 (继承自 Object) |