Question

I have a class which inherits from MarshalByRefObject, and in it I am overriding the lifetime service to give it an InitialLeaseTime of two hours:

public override object InitializeLifetimeService()
{
    // Expire after two hours.
    var lease = (ILease)base.InitializeLifetimeService();
    if (lease.CurrentState == LeaseState.Initial)
        lease.InitialLeaseTime = TimeSpan.FromHours(2);

    return lease;
}

Now, I want to perform some logic when the lease expires. Is there an event or a hook into the expiration? I have searched Google and MSDN, but I have found nothing.

Thanks!

Était-ce utile?

La solution

When a lease expires the ISponsor.Renewal method is being called on the object's sponsor. Thus, you can implement ISponsor yourself and put your logic there.

To do that, you'll need to call the ILease.Register method in your implementation of InitializeLifetimeService, passing your ISponsor as the argument.

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top