ClientSponsor 类

定义

为生存期主办方类提供默认实现。

C#
public class ClientSponsor : MarshalByRefObject, System.Runtime.Remoting.Lifetime.ISponsor
C#
[System.Runtime.InteropServices.ComVisible(true)]
public class ClientSponsor : MarshalByRefObject, System.Runtime.Remoting.Lifetime.ISponsor
C#
[System.Runtime.InteropServices.ComVisible(true)]
[System.Security.SecurityCritical]
public class ClientSponsor : MarshalByRefObject, System.Runtime.Remoting.Lifetime.ISponsor
继承
ClientSponsor
属性
实现

示例

以下示例演示 ClientSponsor 类,以延长类激活远程对象的生存期。

C#
using System;
using System.Runtime.Remoting;
using System.Runtime.Remoting.Channels;
using System.Runtime.Remoting.Channels.Tcp;
using System.Runtime.Remoting.Lifetime;
namespace RemotingSamples
{

   class HelloClient
   {
       static void Main()
      {
         // Register a channel.
         TcpChannel myChannel = new TcpChannel ();
         ChannelServices.RegisterChannel(myChannel);
         RemotingConfiguration.RegisterActivatedClientType(
                                typeof(HelloService),"tcp://localhost:8085/");

         // Get the remote object.
         HelloService myService = new HelloService();

         // Get a sponsor for renewal of time.
         ClientSponsor mySponsor = new ClientSponsor();

         // Register the service with sponsor.
         mySponsor.Register(myService);

         // Set renewaltime.
         mySponsor.RenewalTime = TimeSpan.FromMinutes(2);

         // Renew the lease.
         ILease myLease = (ILease)mySponsor.InitializeLifetimeService();
         TimeSpan myTime = mySponsor.Renewal(myLease);
         Console.WriteLine("Renewed time in minutes is " + myTime.Minutes.ToString());

         // Call the remote method.
         Console.WriteLine(myService.HelloMethod("World"));

         // Unregister the channel.
         mySponsor.Unregister(myService);
         mySponsor.Close();
      }
   }
}

注解

当前生存期发起人实现可用于通过指定所需的续订 TimeSpan来赞助对象。

备注

此类在类级别发出链接需求和继承需求。 SecurityException当直接调用方或派生类没有基础结构权限时,将引发 。 有关安全要求的详细信息,请参阅 链接需求继承需求

构造函数

ClientSponsor()

使用默认值初始化 ClientSponsor 类的新实例。

ClientSponsor(TimeSpan)

用被发起对象的续订时间来初始化 ClientSponsor 类的新实例。

属性

RenewalTime

获取或设置当请求续订时被发起对象的生存期所延长的 TimeSpan

方法

Close()

清空注册到当前 ClientSponsor 的列表对象。

CreateObjRef(Type)

创建一个对象,该对象包含生成用于与远程对象进行通信的代理所需的全部相关信息。

(继承自 MarshalByRefObject)
Equals(Object)

确定指定对象是否等于当前对象。

(继承自 Object)
Finalize()

在垃圾回收器回收当前 ClientSponsor 的资源之前释放它们。

GetHashCode()

作为默认哈希函数。

(继承自 Object)
GetLifetimeService()
已过时.

检索控制此实例的生存期策略的当前生存期服务对象。

(继承自 MarshalByRefObject)
GetType()

获取当前实例的 Type

(继承自 Object)
InitializeLifetimeService()

初始化 ClientSponsor 的新实例,为当前对象提供租约。

MemberwiseClone()

创建当前 Object 的浅表副本。

(继承自 Object)
MemberwiseClone(Boolean)

创建当前 MarshalByRefObject 对象的浅表副本。

(继承自 MarshalByRefObject)
Register(MarshalByRefObject)

为主办关系注册指定的 MarshalByRefObject

Renewal(ILease)

请求发起客户端续订指定对象的租约。

ToString()

返回表示当前对象的字符串。

(继承自 Object)
Unregister(MarshalByRefObject)

从由当前 MarshalByRefObject 发起的对象列表中注销指定的 ClientSponsor

适用于

产品 版本
.NET Framework 1.1, 2.0, 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1