ClientSponsor Class
Provides a default implementation for a lifetime sponsor class.
Assembly: mscorlib (in mscorlib.dll)
| 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(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^) | 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 the default hash function. (Inherited from Object.) |
![]() | GetLifetimeService() | Retrieves the current lifetime service object that controls the lifetime policy for this instance.(Inherited from MarshalByRefObject.) |
![]() | GetType() | |
![]() | InitializeLifetimeService() | Initializes a new instance of ClientSponsor, providing a lease for the current object.(Overrides MarshalByRefObject::InitializeLifetimeService().) |
![]() | MemberwiseClone() | |
![]() | MemberwiseClone(Boolean) | Creates a shallow copy of the current MarshalByRefObject object.(Inherited from MarshalByRefObject.) |
![]() | Register(MarshalByRefObject^) | Registers the specified MarshalByRefObject for sponsorship. |
![]() | Renewal(ILease^) | 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(MarshalByRefObject^) | 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(); }
for operating with infrastructure code. Demand value: SecurityAction::LinkDemand; Permission Value: SecurityPermissionFlag::Infrastructure
for operating with infrastructure code. Demand value: SecurityAction::InheritanceDemand; Permission Value: SecurityPermissionFlag::Infrastructure
Available since 1.1
Any public static ( Shared in Visual Basic) members of this type are thread safe. Any instance members are not guaranteed to be thread safe.



