This documentation is archived and is not being maintained.

ClientSponsor Class

Provides a default implementation for a lifetime sponsor class.


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

[SecurityPermissionAttribute(SecurityAction.InheritanceDemand, Flags = SecurityPermissionFlag.Infrastructure)]
public class ClientSponsor : MarshalByRefObject, 

The ClientSponsor type exposes the following members.

Public methodClientSponsor()Initializes a new instance of the ClientSponsor class with default values.
Public methodClientSponsor(TimeSpan)Initializes a new instance of the ClientSponsor class with the renewal time of the sponsored object.

Public propertyRenewalTimeGets or sets the TimeSpan by which to increase the lifetime of the sponsored objects when renewal is requested.

Public methodCloseEmpties the list objects registered with the current ClientSponsor.
Public methodCreateObjRefCreates an object that contains all the relevant information required to generate a proxy used to communicate with a remote object. (Inherited from MarshalByRefObject.)
Public methodEquals(Object)Determines whether the specified Object is equal to the current Object. (Inherited from Object.)
Protected methodFinalizeFrees the resources of the current ClientSponsor before the garbage collector reclaims them. (Overrides Object.Finalize().)
Public methodGetHashCodeServes as a hash function for a particular type. (Inherited from Object.)
Public methodGetLifetimeServiceRetrieves the current lifetime service object that controls the lifetime policy for this instance. (Inherited from MarshalByRefObject.)
Public methodGetTypeGets the Type of the current instance. (Inherited from Object.)
Public methodInitializeLifetimeServiceInitializes a new instance of ClientSponsor, providing a lease for the current object. (Overrides MarshalByRefObject.InitializeLifetimeService().)
Protected methodMemberwiseClone()Creates a shallow copy of the current Object. (Inherited from Object.)
Protected methodMemberwiseClone(Boolean)Creates a shallow copy of the current MarshalByRefObject object. (Inherited from MarshalByRefObject.)
Public methodRegisterRegisters the specified MarshalByRefObject for sponsorship.
Public methodRenewalRequests a sponsoring client to renew the lease for the specified object.
Public methodToStringReturns a string that represents the current object. (Inherited from Object.)
Public methodUnregisterUnregisters the specified MarshalByRefObject from the list of objects sponsored by the current ClientSponsor.

The current lifetime sponsor implementation can be used to sponsor objects by specifying the required renewal TimeSpan.


This class makes a link demand and an inheritance demand at the class level. A SecurityException is thrown when either the immediate caller or the derived class does not have infrastructure permission. For details about security demands, see Link Demands and Inheritance Demands.

The following example illustrates the ClientSponsor class to extend the life of a class-activated remote object.

using System;
using System.Runtime.Remoting;
using System.Runtime.Remoting.Channels;
using System.Runtime.Remoting.Channels.Tcp;
using System.Runtime.Remoting.Lifetime;
namespace RemotingSamples

   class HelloClient
       static void Main()
         // Register a channel.
         TcpChannel myChannel = new TcpChannel ();

         // Get the remote object.
         HelloService myService = new HelloService();

         // Get a sponsor for renewal of time.
         ClientSponsor mySponsor = new ClientSponsor();

         // Register the service with sponsor.

         // Set renewaltime.
         mySponsor.RenewalTime = TimeSpan.FromMinutes(2);

         // Renew the lease.
         ILease myLease = (ILease)mySponsor.InitializeLifetimeService();
         TimeSpan myTime = mySponsor.Renewal(myLease);
         Console.WriteLine("Renewed time in minutes is " + myTime.Minutes.ToString());

         // Call the remote method.

         // Unregister the channel.


.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.