ClientSponsor ClientSponsor ClientSponsor ClientSponsor Class


Provides a default implementation for a lifetime sponsor class.

public ref class ClientSponsor : MarshalByRefObject, System::Runtime::Remoting::Lifetime::ISponsor
public class ClientSponsor : MarshalByRefObject, System.Runtime.Remoting.Lifetime.ISponsor
type ClientSponsor = class
    inherit MarshalByRefObject
    interface ISponsor
Public Class ClientSponsor
Inherits MarshalByRefObject
Implements ISponsor


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

#using <system.dll>
#using <system.runtime.remoting.dll>
#using <ClientSponsor_Share.dll>

using namespace System;
using namespace System::Runtime::Remoting;
using namespace System::Runtime::Remoting::Channels;
using namespace System::Runtime::Remoting::Channels::Tcp;
using namespace System::Runtime::Remoting::Lifetime;

int main()
   // Register a channel.
   TcpChannel^ myChannel = gcnew TcpChannel;
   ChannelServices::RegisterChannel( myChannel );
      RemotingSamples::HelloService::typeid, "tcp://localhost:8085/" );
   // Get the remote Object*.
   RemotingSamples::HelloService ^ myService = gcnew RemotingSamples::HelloService;
   // Get a sponsor for renewal of time.
   ClientSponsor^ mySponsor = gcnew ClientSponsor;
   // Register the service with sponsor.
   mySponsor->Register( myService );
   // Set renewaltime.
   mySponsor->RenewalTime = TimeSpan::FromMinutes( 2 );
   // Renew the lease.
   ILease^ myLease = dynamic_cast<ILease^>(mySponsor->InitializeLifetimeService());
   TimeSpan myTime = mySponsor->Renewal( myLease );
   Console::WriteLine( "Renewed time in minutes is {0}", myTime.Minutes );
   // Call the remote method.
   Console::WriteLine( myService->HelloMethod( "World" ) );
   // Unregister the channel.
   mySponsor->Unregister( myService );
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.

Imports System
Imports System.Runtime.Remoting
Imports System.Runtime.Remoting.Channels
Imports System.Runtime.Remoting.Channels.Tcp
Imports System.Runtime.Remoting.Lifetime

Namespace RemotingSamples

   Class HelloClient

      Shared Sub Main()
         ' Register a channel.
         Dim myChannel As New TcpChannel()
         RemotingConfiguration.RegisterActivatedClientType( _
                     GetType(HelloService), "tcp://localhost:8085")

         ' Get the remote object.
         Dim myService As New HelloService()

         ' Get a sponsor for renewal of time.
         Dim mySponsor As New ClientSponsor()

         ' Register the service with sponsor.

         ' Set renewaltime.
         mySponsor.RenewalTime = TimeSpan.FromMinutes(2)

         ' Renew the lease.
         Dim myLease As ILease = CType(mySponsor.InitializeLifetimeService(), ILease)
         Dim myTime As TimeSpan = mySponsor.Renewal(myLease)
         Console.WriteLine("Renewed time in minutes is " & myTime.Minutes)

         ' Call the remote method.

         ' Unregister the channel.
      End Sub 'Main
   End Class 'HelloClient

End Namespace 'RemotingSamples


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.


ClientSponsor() ClientSponsor() ClientSponsor() ClientSponsor()

Initializes a new instance of the ClientSponsor class with default values.

ClientSponsor(TimeSpan) ClientSponsor(TimeSpan) ClientSponsor(TimeSpan) ClientSponsor(TimeSpan)

Initializes a new instance of the ClientSponsor class with the renewal time of the sponsored object.


RenewalTime RenewalTime RenewalTime RenewalTime

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


Close() Close() Close() Close()

Empties the list objects registered with the current ClientSponsor.

CreateObjRef(Type) CreateObjRef(Type) CreateObjRef(Type) CreateObjRef(Type)

Creates an object that contains all the relevant information required to generate a proxy used to communicate with a remote object.

(Inherited from MarshalByRefObject)
Equals(Object) Equals(Object) Equals(Object) Equals(Object)

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

(Inherited from Object)
Finalize() Finalize() Finalize() Finalize()

Frees the resources of the current ClientSponsor before the garbage collector reclaims them.

GetHashCode() GetHashCode() GetHashCode() GetHashCode()

Serves as the default hash function.

(Inherited from Object)
GetLifetimeService() GetLifetimeService() GetLifetimeService() GetLifetimeService()

Retrieves the current lifetime service object that controls the lifetime policy for this instance.

(Inherited from MarshalByRefObject)
GetType() GetType() GetType() GetType()

Gets the Type of the current instance.

(Inherited from Object)
InitializeLifetimeService() InitializeLifetimeService() InitializeLifetimeService() InitializeLifetimeService()

Initializes a new instance of ClientSponsor, providing a lease for the current object.

MemberwiseClone() MemberwiseClone() MemberwiseClone() MemberwiseClone()

Creates a shallow copy of the current Object.

(Inherited from Object)
MemberwiseClone(Boolean) MemberwiseClone(Boolean) MemberwiseClone(Boolean) MemberwiseClone(Boolean)

Creates a shallow copy of the current MarshalByRefObject object.

(Inherited from MarshalByRefObject)
Register(MarshalByRefObject) Register(MarshalByRefObject) Register(MarshalByRefObject) Register(MarshalByRefObject)

Registers the specified MarshalByRefObject for sponsorship.

Renewal(ILease) Renewal(ILease) Renewal(ILease) Renewal(ILease)

Requests a sponsoring client to renew the lease for the specified object.

ToString() ToString() ToString() ToString()

Returns a string that represents the current object.

(Inherited from Object)
Unregister(MarshalByRefObject) Unregister(MarshalByRefObject) Unregister(MarshalByRefObject) Unregister(MarshalByRefObject)

Unregisters the specified MarshalByRefObject from the list of objects sponsored by the current ClientSponsor.


for operating with infrastructure code. Demand value: InheritanceDemand; Permission Value: Infrastructure

Applies to