Export (0) Print
Expand All

LifetimeServices Class

Controls the.NET remoting lifetime services.

System.Object
  System.Runtime.Remoting.Lifetime.LifetimeServices

Namespace:  System.Runtime.Remoting.Lifetime
Assembly:  mscorlib (in mscorlib.dll)

[ComVisibleAttribute(true)]
public sealed class LifetimeServices

The LifetimeServices type exposes the following members.

  NameDescription
Public methodLifetimeServices Obsolete. Creates an instance of LifetimeServices.
Top

  NameDescription
Public propertyStatic memberLeaseManagerPollTimeGets or sets the time interval between each activation of the lease manager to clean up expired leases.
Public propertyStatic memberLeaseTimeGets or sets the initial lease time span for an AppDomain.
Public propertyStatic memberRenewOnCallTimeGets or sets the amount of time by which the lease is extended every time a call comes in on the server object.
Public propertyStatic memberSponsorshipTimeoutGets or sets the amount of time the lease manager waits for a sponsor to return with a lease renewal time.
Top

  NameDescription
Public methodEquals(Object)Determines whether the specified Object is equal to the current Object. (Inherited from Object.)
Protected methodFinalizeAllows an object to try to free resources and perform other cleanup operations before it is reclaimed by garbage collection. (Inherited from Object.)
Public methodGetHashCodeServes as a hash function for a particular type. (Inherited from Object.)
Public methodGetTypeGets the Type of the current instance. (Inherited from Object.)
Protected methodMemberwiseCloneCreates a shallow copy of the current Object. (Inherited from Object.)
Public methodToStringReturns a string that represents the current object. (Inherited from Object.)
Top

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.

NoteNote

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.


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();
   }
}


.NET Framework

Supported in: 4, 3.5, 3.0, 2.0, 1.1, 1.0

.NET Framework Client Profile

Supported in: 4, 3.5 SP1

Windows 7, Windows Vista SP1 or later, Windows XP SP3, Windows XP SP2 x64 Edition, Windows Server 2008 (Server Core not supported), Windows Server 2008 R2 (Server Core supported with SP1 or later), Windows Server 2003 SP2

The .NET Framework does not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.

Any public static (Shared in Visual Basic) members of this type are thread safe. Any instance members are not guaranteed to be thread safe.
Was this page helpful?
(1500 characters remaining)
Thank you for your feedback

Community Additions

Show:
© 2014 Microsoft