LifetimeServices Class
Controls the.NET remoting lifetime services.
Assembly: mscorlib (in mscorlib.dll)
Distributed garbage collection is responsible for controlling the lifetimes of server applications, and for deleting them when their lifetimes have expired. 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.
Note: |
|---|
This class makes a link demand. A SecurityException is thrown if the immediate caller does not have infrastructure permission. See Link Demands for more information. |
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
#using <mscorlib.dll>
#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(new HttpChannel(8080));
RemotingConfiguration::RegisterActivatedServiceType(__typeof(ClientActivatedType));
Console::WriteLine(S"The server is listening. Press Enter to exit....");
Console::ReadLine();
Console::WriteLine(S"GC'ing.");
GC::Collect();
GC::WaitForPendingFinalizers();
return 0;
}
- SecurityPermission
for operating with infrastructure code. Demand value: SecurityAction.LinkDemand; Permission Value: SecurityPermissionFlag.Infrastructure
Windows 7, Windows Vista, Windows XP SP2, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP Starter Edition, Windows Server 2008 R2, Windows Server 2008, Windows Server 2003, Windows Server 2000 SP4, Windows Millennium Edition, Windows 98
The .NET Framework and .NET Compact Framework do not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.
Note: