LifetimeServices Class
Controls the .NET remoting lifetime services.
For a list of all members of this type, see LifetimeServices Members.
System.Object
System.Runtime.Remoting.Lifetime.LifetimeServices
[Visual Basic] NotInheritable Public Class LifetimeServices [C#] public sealed class LifetimeServices [C++] public __gc __sealed class LifetimeServices [JScript] public class LifetimeServices
Thread Safety
Any public static (Shared in Visual Basic) members of this type are thread safe. Any instance members are not guaranteed to be thread safe.
Remarks
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.
Example
[Visual Basic] 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 [C#] 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(); } } [C++] #using <mscorlib.dll> #using <system.dll> #using <system.runtime.remoting.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; }
[JScript] No example is available for JScript. To view a Visual Basic, C#, or C++ example, click the Language Filter button
in the upper-left corner of the page.
Requirements
Namespace: System.Runtime.Remoting.Lifetime
Platforms: Windows 98, Windows NT 4.0, Windows Millennium Edition, Windows 2000, Windows XP Home Edition, Windows XP Professional, Windows Server 2003 family
Assembly: Mscorlib (in Mscorlib.dll)
.NET Framework Security:
- SecurityPermission for operating with infrastructure code. Demand value: SecurityAction.LinkDemand; Permission Value: SecurityPermissionFlag.Infrastructure
See Also
LifetimeServices Members | System.Runtime.Remoting.Lifetime Namespace