ClientSponsor.Renewal(ILease) 方法 - Microsoft Docs

文章推薦指數: 80 %
投票人數:10人

要求贊助的用戶端更新指定物件的使用期。

跳到主要內容 已不再支援此瀏覽器。

請升級至MicrosoftEdge,以利用最新功能、安全性更新和技術支援。

下載MicrosoftEdge 其他資訊 目錄 結束焦點模式 語言 閱讀英文 儲存 目錄 閱讀英文 儲存 編輯 Twitter LinkedIn Facebook 電子郵件 目錄 ClientSponsor.Renewal(ILease)方法 參考 定義 命名空間: System.Runtime.Remoting.Lifetime 組件:mscorlib.dll 重要 部分資訊涉及發行前產品,在發行之前可能會有大幅修改。

Microsoft對此處提供的資訊,不做任何明確或隱含的瑕疵擔保。

本文內容 要求贊助的用戶端更新指定物件的使用期。

public: virtualTimeSpanRenewal(System::Runtime::Remoting::Lifetime::ILease^lease); publicTimeSpanRenewal(System.Runtime.Remoting.Lifetime.ILeaselease); [System.Security.SecurityCritical] publicTimeSpanRenewal(System.Runtime.Remoting.Lifetime.ILeaselease); abstractmemberRenewal:System.Runtime.Remoting.Lifetime.ILease->TimeSpan overridethis.Renewal:System.Runtime.Remoting.Lifetime.ILease->TimeSpan [] abstractmemberRenewal:System.Runtime.Remoting.Lifetime.ILease->TimeSpan overridethis.Renewal:System.Runtime.Remoting.Lifetime.ILease->TimeSpan PublicFunctionRenewal(leaseAsILease)AsTimeSpan 參數 lease ILease 需要使用期更新的物件的存留期使用期。

傳回 TimeSpan 指定的物件的額外使用期時間。

實作 Renewal(ILease) 屬性 SecurityCriticalAttribute 範例 intmain() { //Registerachannel. TcpChannel^myChannel=gcnewTcpChannel; ChannelServices::RegisterChannel(myChannel); RemotingConfiguration::RegisterActivatedClientType( RemotingSamples::HelloService::typeid,"tcp://localhost:8085/"); //GettheremoteObject*. RemotingSamples::HelloService^myService=gcnewRemotingSamples::HelloService; //Getasponsorforrenewaloftime. ClientSponsor^mySponsor=gcnewClientSponsor; //Registertheservicewithsponsor. mySponsor->Register(myService); //Setrenewaltime. mySponsor->RenewalTime=TimeSpan::FromMinutes(2); //Renewthelease. ILease^myLease=dynamic_cast(mySponsor->InitializeLifetimeService()); TimeSpanmyTime=mySponsor->Renewal(myLease); Console::WriteLine("Renewedtimeinminutesis{0}",myTime.Minutes); //Calltheremotemethod. Console::WriteLine(myService->HelloMethod("World")); //Unregisterthechannel. mySponsor->Unregister(myService); mySponsor->Close(); } classHelloClient { staticvoidMain() { //Registerachannel. TcpChannelmyChannel=newTcpChannel(); ChannelServices.RegisterChannel(myChannel); RemotingConfiguration.RegisterActivatedClientType( typeof(HelloService),"tcp://localhost:8085/"); //Gettheremoteobject. HelloServicemyService=newHelloService(); //Getasponsorforrenewaloftime. ClientSponsormySponsor=newClientSponsor(); //Registertheservicewithsponsor. mySponsor.Register(myService); //Setrenewaltime. mySponsor.RenewalTime=TimeSpan.FromMinutes(2); //Renewthelease. ILeasemyLease=(ILease)mySponsor.InitializeLifetimeService(); TimeSpanmyTime=mySponsor.Renewal(myLease); Console.WriteLine("Renewedtimeinminutesis"+myTime.Minutes.ToString()); //Calltheremotemethod. Console.WriteLine(myService.HelloMethod("World")); //Unregisterthechannel. mySponsor.Unregister(myService); mySponsor.Close(); } } ClassHelloClient SharedSubMain() 'Registerachannel. DimmyChannelAsNewTcpChannel() ChannelServices.RegisterChannel(myChannel) RemotingConfiguration.RegisterActivatedClientType(_ GetType(HelloService),"tcp://localhost:8085") 'Gettheremoteobject. DimmyServiceAsNewHelloService() 'Getasponsorforrenewaloftime. DimmySponsorAsNewClientSponsor() 'Registertheservicewithsponsor. mySponsor.Register(myService) 'Setrenewaltime. mySponsor.RenewalTime=TimeSpan.FromMinutes(2) 'Renewthelease. DimmyLeaseAsILease=CType(mySponsor.InitializeLifetimeService(),ILease) DimmyTimeAsTimeSpan=mySponsor.Renewal(myLease) Console.WriteLine("Renewedtimeinminutesis"&myTime.Minutes) 'Calltheremotemethod. Console.WriteLine(myService.HelloMethod("World")) 'Unregisterthechannel. mySponsor.Unregister(myService) mySponsor.Close() EndSub EndClass 備註 分散式Renewal垃圾收集行程會呼叫方法,以更新指定物件的租用。

適用於 本文內容



請為這篇文章評分?