Comment : Substituer l'interface InitializeLifetimeService
Cet exemple de code illustre une substitution standard de l'interface InitializeLifetimeService.
Exemple
Public Class MyLifetimeControlObject
Inherits MarshalByRefObject
Public Overrides Function InitializeLifetimeService() As [Object]
Dim lease As ILease = CType(MyBase.InitializeLifetimeService(), ILease)
If lease.CurrentState = LeaseState.Initial Then
lease.InitialLeaseTime = TimeSpan.FromMinutes(1)
lease.SponsorshipTimeout = TimeSpan.FromMinutes(2)
lease.RenewOnCallTime = TimeSpan.FromSeconds(2)
End If
Return lease
End Function 'InitializeLifetimeService
End Class 'MyLifetimeControlObject
public class MyLifetimeControlObject: MarshalByRefObject {
public override Object InitializeLifetimeService()
{
ILease lease = (ILease)base.InitializeLifetimeService();
if (lease.CurrentState == LeaseState.Initial) {
lease.InitialLeaseTime = TimeSpan.FromMinutes(1);
lease.SponsorshipTimeout = TimeSpan.FromMinutes(2);
lease.RenewOnCallTime = TimeSpan.FromSeconds(2);
}
return lease;
}
}
Compilation du code
Cet exemple nécessite :
- Des références à l'espace de noms System.Runtime.Remoting.Lifetime.