Rediger

Del via


LifetimeServices Class

Definition

Controls the.NET remoting lifetime services.

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
Inheritance
LifetimeServices
Attributes

Examples

#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

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.

Constructors

LifetimeServices()
Obsolete.

Creates an instance of LifetimeServices.

Properties

LeaseManagerPollTime

Gets or sets the time interval between each activation of the lease manager to clean up expired leases.

LeaseTime

Gets or sets the initial lease time span for an AppDomain.

RenewOnCallTime

Gets or sets the amount of time by which the lease is extended every time a call comes in on the server object.

SponsorshipTimeout

Gets or sets the amount of time the lease manager waits for a sponsor to return with a lease renewal time.

Methods

Equals(Object)

Determines whether the specified object is equal to the current object.

(Inherited from Object)
GetHashCode()

Serves as the default hash function.

(Inherited from Object)
GetType()

Gets the Type of the current instance.

(Inherited from Object)
MemberwiseClone()

Creates a shallow copy of the current Object.

(Inherited from Object)
ToString()

Returns a string that represents the current object.

(Inherited from Object)

Applies to