문제

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!

도움이 되었습니까?

해결책

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.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top