使用代码配置租约
public override Object InitializeLifetimeService()
2 {
3
4 ILease lease = (ILease)base.InitializeLifetimeService();
5 // Normally, the initial lease time would be much longer.
6 // It is shortened here for demonstration purposes.
7 if (lease.CurrentState == LeaseState.Initial)
8 {
9 lease.InitialLeaseTime = TimeSpan.FromSeconds(3);
10 lease.SponsorshipTimeout = TimeSpan.FromSeconds(10);
11 lease.RenewOnCallTime = TimeSpan.FromSeconds(2);
12 }
13 return lease;
14 }
2 {
3
4 ILease lease = (ILease)base.InitializeLifetimeService();
5 // Normally, the initial lease time would be much longer.
6 // It is shortened here for demonstration purposes.
7 if (lease.CurrentState == LeaseState.Initial)
8 {
9 lease.InitialLeaseTime = TimeSpan.FromSeconds(3);
10 lease.SponsorshipTimeout = TimeSpan.FromSeconds(10);
11 lease.RenewOnCallTime = TimeSpan.FromSeconds(2);
12 }
13 return lease;
14 }
如果需要租约无限期长,只要返回return nothing或者设置为0即可