18.9 Controlling Lifetime Leases

 <  Day Day Up  >  

You want to change the default values that specify the lease times for a remote object on the server.


Technique

You can change the default values for the lease time configurations by setting the <lifetime> element in the .NET Remoting configuration file, as shown here. Setting the leaseTime attribute to 15M defines a lease time of 15 minutes instead of the default 300 seconds. The value defined with renewOnCallTime specifies the time that the lease time is incremented with every method call:

 
 <?xml version="1.0" encoding="utf-8" ?> <configuration>     <system.runtime.remoting>         <application>             <lifetime leaseTime="15M" renewOnCallTime="3M" />         </application>     </system.runtime.remoting> </configuration> 

You can also specify lease-time values with the remoting object instead. You have to override the method InitializeLifetimeService of the base class MarshalByRefObject , where you can change the lease values using the ILease interface:

 
 public class RemoteObject : MarshalByRefObject {     public string Greeting(string name)     {         return "Hello " + name;     }     public override object InitializeLifetimeService()     {         ILease lease = (ILease)base.InitializeLifetimeService();         lease.InitialLeaseTime = TimeSpan.FromMinutes(20);         lease.RenewOnCallTime = TimeSpan.FromSeconds(50);         return lease;     } } 

Comments

For the lease time, you use four configuration values. The lease time has a default initial value of 300 seconds that is also the maximum value. Every time a method is called, the lease time is incremented by 120 seconds up to the maximum lease time.

You can change these values by setting new values in the configuration file or by overriding the method InitializeLifetimeService . The values set directly in the object class override the values in the configuration file.

Leasing applies only to stateful objects. Well-known single-call objects are created with every method call, so leasing does not apply here.

 <  Day Day Up  >  


Microsoft Visual C# .Net 2003
Microsoft Visual C *. NET 2003 development skills Daquan
ISBN: 7508427505
EAN: 2147483647
Year: 2003
Pages: 440

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net