ISponsor 接口
指示该实施者希望成为生存期租约主办方。
**命名空间:**System.Runtime.Remoting.Lifetime
**程序集:**mscorlib(在 mscorlib.dll 中)
语法
声明
<ComVisibleAttribute(True)> _
Public Interface ISponsor
用法
Dim instance As ISponsor
[ComVisibleAttribute(true)]
public interface ISponsor
[ComVisibleAttribute(true)]
public interface class ISponsor
/** @attribute ComVisibleAttribute(true) */
public interface ISponsor
ComVisibleAttribute(true)
public interface ISponsor
备注
如果对象需要为特定对象请求租约续订,则它必须实现 ISponsor 接口。实现 ISponsor 接口的对象可以通过将自身注册到租约管理器来成为主办方。ISponsor 接口由生存期服务用于回调到该主办方。
示例
Public Class MyClientSponsor
Inherits MarshalByRefObject
Implements ISponsor
Private lastRenewal As DateTime
Public Sub New()
lastRenewal = DateTime.Now
End Sub 'New
<SecurityPermission(SecurityAction.LinkDemand, Flags := SecurityPermissionFlag.Infrastructure)> _
Public Function Renewal(lease As ILease) As TimeSpan Implements ISponsor.Renewal
Console.WriteLine("Request to renew the lease time.")
Console.WriteLine("Time since last renewal: " + _
DateTime.op_Subtraction(DateTime.Now, lastRenewal).ToString())
lastRenewal = DateTime.Now
Return TimeSpan.FromSeconds(20)
End Function 'Renewal
End Class 'MyClientSponsor
public class MyClientSponsor : MarshalByRefObject, ISponsor
{
private DateTime lastRenewal;
public MyClientSponsor()
{
lastRenewal = DateTime.Now;
}
[SecurityPermissionAttribute(SecurityAction.LinkDemand, Flags=SecurityPermissionFlag.Infrastructure)]
public TimeSpan Renewal(ILease lease)
{
Console.WriteLine("Request to renew the lease time.");
Console.WriteLine("Time since last renewal: " +
(DateTime.Now - lastRenewal).ToString());
lastRenewal = DateTime.Now;
return TimeSpan.FromSeconds(20);
}
}
public ref class MyClientSponsor: public MarshalByRefObject, public ISponsor
{
private:
DateTime lastRenewal;
public:
MyClientSponsor()
{
lastRenewal = DateTime::Now;
}
[SecurityPermissionAttribute(SecurityAction::LinkDemand,Flags=SecurityPermissionFlag::Infrastructure)]
virtual TimeSpan Renewal( ILease^ /* lease */ )
{
Console::WriteLine( "Request to renew the lease time." );
Console::WriteLine( "Time since last renewal: {0}",
DateTime::Now - lastRenewal );
lastRenewal = DateTime::Now;
return TimeSpan::FromSeconds( 20 );
}
};
平台
Windows 98、Windows 2000 SP4、Windows Millennium Edition、Windows Server 2003、Windows XP Media Center Edition、Windows XP Professional x64 Edition、Windows XP SP2、Windows XP Starter Edition
.NET Framework 并不是对每个平台的所有版本都提供支持。有关受支持版本的列表,请参见系统要求。
版本信息
.NET Framework
受以下版本支持:2.0、1.1、1.0