ClientSponsor Class
Provides a default implementation for a lifetime sponsor class.
Assembly: mscorlib (in mscorlib.dll)
The ClientSponsor type exposes the following members.
| Name | Description | |
|---|---|---|
![]() | ClientSponsor() | Initializes a new instance of the ClientSponsor class with default values. |
![]() | ClientSponsor(TimeSpan) | Initializes a new instance of the ClientSponsor class with the renewal time of the sponsored object. |
| Name | Description | |
|---|---|---|
![]() | RenewalTime | Gets or sets the TimeSpan by which to increase the lifetime of the sponsored objects when renewal is requested. |
| Name | Description | |
|---|---|---|
![]() | Close | Empties the list objects registered with the current ClientSponsor. |
![]() | CreateObjRef | 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) | Determines whether the specified Object is equal to the current Object. (Inherited from Object.) |
![]() | Finalize | Frees the resources of the current ClientSponsor before the garbage collector reclaims them. (Overrides Object::Finalize().) |
![]() | GetHashCode | Serves as a hash function for a particular type. (Inherited from Object.) |
![]() | GetLifetimeService | Retrieves the current lifetime service object that controls the lifetime policy for this instance. (Inherited from MarshalByRefObject.) |
![]() | GetType | Gets the Type of the current instance. (Inherited from Object.) |
![]() | InitializeLifetimeService | Initializes a new instance of ClientSponsor, providing a lease for the current object. (Overrides MarshalByRefObject::InitializeLifetimeService().) |
![]() | MemberwiseClone() | Creates a shallow copy of the current Object. (Inherited from Object.) |
![]() | MemberwiseClone(Boolean) | Creates a shallow copy of the current MarshalByRefObject object. (Inherited from MarshalByRefObject.) |
![]() | Register | Registers the specified MarshalByRefObject for sponsorship. |
![]() | Renewal | Requests a sponsoring client to renew the lease for the specified object. |
![]() | ToString | Returns a string that represents the current object. (Inherited from Object.) |
![]() | Unregister | Unregisters 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.
Note |
|---|
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.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 ); RemotingConfiguration::RegisterActivatedClientType( 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 ); mySponsor->Close(); }
- SecurityPermission
for operating with infrastructure code. Demand value: SecurityAction::LinkDemand; Permission Value: SecurityPermissionFlag::Infrastructure
- SecurityPermission
for operating with infrastructure code. Demand value: SecurityAction::InheritanceDemand; Permission Value: SecurityPermissionFlag::Infrastructure
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.
