mscorlib(4.0.0.0) API with additions
ClientSponsor.cs
1 using System.Collections;
3 using System.Security;
5 
7 {
9  [SecurityCritical]
10  [ComVisible(true)]
11  [SecurityPermission(SecurityAction.InheritanceDemand, Flags = SecurityPermissionFlag.Infrastructure)]
13  {
14  private Hashtable sponsorTable = new Hashtable(10);
15 
16  private TimeSpan m_renewalTime = TimeSpan.FromMinutes(2.0);
17 
20  public TimeSpan RenewalTime
21  {
22  get
23  {
24  return m_renewalTime;
25  }
26  set
27  {
28  m_renewalTime = value;
29  }
30  }
31 
33  public ClientSponsor()
34  {
35  }
36 
39  public ClientSponsor(TimeSpan renewalTime)
40  {
41  m_renewalTime = renewalTime;
42  }
43 
48  [SecurityCritical]
49  public bool Register(MarshalByRefObject obj)
50  {
51  ILease lease = (ILease)obj.GetLifetimeService();
52  if (lease == null)
53  {
54  return false;
55  }
56  lease.Register(this);
57  lock (sponsorTable)
58  {
59  sponsorTable[obj] = lease;
60  }
61  return true;
62  }
63 
66  [SecurityCritical]
67  public void Unregister(MarshalByRefObject obj)
68  {
69  ILease lease = null;
70  lock (sponsorTable)
71  {
72  lease = (ILease)sponsorTable[obj];
73  }
74  lease?.Unregister(this);
75  }
76 
80  [SecurityCritical]
81  public TimeSpan Renewal(ILease lease)
82  {
83  return m_renewalTime;
84  }
85 
87  [SecurityCritical]
88  public void Close()
89  {
90  lock (sponsorTable)
91  {
92  IDictionaryEnumerator enumerator = sponsorTable.GetEnumerator();
93  while (enumerator.MoveNext())
94  {
95  ((ILease)enumerator.Value).Unregister(this);
96  }
97  sponsorTable.Clear();
98  }
99  }
100 
103  [SecurityCritical]
104  public override object InitializeLifetimeService()
105  {
106  return null;
107  }
108 
110  [SecuritySafeCritical]
111  ~ClientSponsor()
112  {
113  }
114  }
115 }
Describes a set of security permissions applied to code. This class cannot be inherited.
Defines a lifetime lease object that is used by the remoting lifetime service.
Definition: ILease.cs:8
bool MoveNext()
Advances the enumerator to the next element of the collection.
Indicates that the implementer wants to be a lifetime lease sponsor.
Definition: ISponsor.cs:8
ClientSponsor(TimeSpan renewalTime)
Initializes a new instance of the T:System.Runtime.Remoting.Lifetime.ClientSponsor class with the ren...
void Register(ISponsor obj, TimeSpan renewalTime)
Registers a sponsor for the lease, and renews it by the specified T:System.TimeSpan.
Definition: __Canon.cs:3
TimeSpan Renewal(ILease lease)
Requests a sponsoring client to renew the lease for the specified object.
void Unregister(ISponsor obj)
Removes a sponsor from the sponsor list.
static TimeSpan FromMinutes(double value)
Returns a T:System.TimeSpan that represents a specified number of minutes, where the specification is...
Definition: TimeSpan.cs:492
void Unregister(MarshalByRefObject obj)
Unregisters the specified T:System.MarshalByRefObject from the list of objects sponsored by the curre...
SecurityAction
Specifies the security actions that can be performed using declarative security.
bool Register(MarshalByRefObject obj)
Registers the specified T:System.MarshalByRefObject for sponsorship.
Provides a default implementation for a lifetime sponsor class.
Represents a collection of key/value pairs that are organized based on the hash code of the key....
Definition: Hashtable.cs:17
object Value
Gets the value of the current dictionary entry.
override object InitializeLifetimeService()
Initializes a new instance of T:System.Runtime.Remoting.Lifetime.ClientSponsor, providing a lease for...
Represents a time interval.To browse the .NET Framework source code for this type,...
Definition: TimeSpan.cs:12
Enumerates the elements of a nongeneric dictionary.
ClientSponsor()
Initializes a new instance of the T:System.Runtime.Remoting.Lifetime.ClientSponsor class with default...
virtual void Clear()
Removes all elements from the T:System.Collections.Hashtable.
Definition: Hashtable.cs:924
TimeSpan RenewalTime
Gets or sets the T:System.TimeSpan by which to increase the lifetime of the sponsored objects when re...
SecurityPermissionFlag
Specifies access flags for the security permission object.
void Close()
Empties the list objects registered with the current T:System.Runtime.Remoting.Lifetime....
Enables access to objects across application domain boundaries in applications that support remoting.