LifetimeServices 類別
定義
重要
部分資訊涉及發行前產品,在發行之前可能會有大幅修改。 Microsoft 對此處提供的資訊,不做任何明確或隱含的瑕疵擔保。
控制.NET遠端終身服務。
public ref class LifetimeServices sealed
public sealed class LifetimeServices
[System.Runtime.InteropServices.ComVisible(true)]
public sealed class LifetimeServices
[System.Runtime.InteropServices.ComVisible(true)]
[System.Security.SecurityCritical]
public sealed class LifetimeServices
type LifetimeServices = class
[<System.Runtime.InteropServices.ComVisible(true)>]
type LifetimeServices = class
[<System.Runtime.InteropServices.ComVisible(true)>]
[<System.Security.SecurityCritical>]
type LifetimeServices = class
Public NotInheritable Class LifetimeServices
- 繼承
-
LifetimeServices
- 屬性
範例
#using <system.dll>
#using <system.runtime.remoting.dll>
#using "service.dll"
using namespace System;
using namespace System::Runtime::Remoting;
using namespace System::Runtime::Remoting::Channels;
using namespace System::Runtime::Remoting::Channels::Http;
using namespace System::Runtime::Remoting::Lifetime;
int main()
{
LifetimeServices::LeaseTime = TimeSpan::FromSeconds( 5 );
LifetimeServices::LeaseManagerPollTime = TimeSpan::FromSeconds( 3 );
LifetimeServices::RenewOnCallTime = TimeSpan::FromSeconds( 2 );
LifetimeServices::SponsorshipTimeout = TimeSpan::FromSeconds( 1 );
ChannelServices::RegisterChannel( gcnew HttpChannel( 8080 ) );
RemotingConfiguration::RegisterActivatedServiceType( ClientActivatedType::typeid );
Console::WriteLine( "The server is listening. Press Enter to exit...." );
Console::ReadLine();
Console::WriteLine( "GC'ing." );
GC::Collect();
GC::WaitForPendingFinalizers();
return 0;
}
using System;
using System.Runtime.Remoting;
using System.Runtime.Remoting.Channels;
using System.Runtime.Remoting.Channels.Http;
using System.Runtime.Remoting.Lifetime;
public class Server {
public static void Main() {
Server myServer = new Server();
myServer.Run();
}
public void Run()
{
LifetimeServices.LeaseTime = TimeSpan.FromSeconds(5);
LifetimeServices.LeaseManagerPollTime = TimeSpan.FromSeconds(3);
LifetimeServices.RenewOnCallTime = TimeSpan.FromSeconds(2);
LifetimeServices.SponsorshipTimeout = TimeSpan.FromSeconds(1);
ChannelServices.RegisterChannel(new HttpChannel(8080), true);
RemotingConfiguration.RegisterActivatedServiceType(typeof(ClientActivatedType));
Console.WriteLine("The server is listening. Press Enter to exit....");
Console.ReadLine();
Console.WriteLine("GC'ing.");
GC.Collect();
GC.WaitForPendingFinalizers();
}
}
Imports System.Runtime.Remoting
Imports System.Runtime.Remoting.Channels
Imports System.Runtime.Remoting.Channels.Http
Imports System.Runtime.Remoting.Lifetime
Imports System.Security.Permissions
Public Class Server
Public Shared Sub Main()
Dim myServer As New Server()
myServer.Run()
End Sub
<SecurityPermission(SecurityAction.Demand, Flags:=SecurityPermissionFlag.Infrastructure)> _
Public Sub Run()
LifetimeServices.LeaseTime = TimeSpan.FromSeconds(5)
LifetimeServices.LeaseManagerPollTime = TimeSpan.FromSeconds(3)
LifetimeServices.RenewOnCallTime = TimeSpan.FromSeconds(2)
LifetimeServices.SponsorshipTimeout = TimeSpan.FromSeconds(1)
ChannelServices.RegisterChannel(New HttpChannel(8080), True)
RemotingConfiguration.RegisterActivatedServiceType(GetType(ClientActivatedType))
Console.WriteLine("The server is listening. Press Enter to exit....")
Console.ReadLine()
Console.WriteLine("GC'ing.")
GC.Collect()
GC.WaitForPendingFinalizers()
End Sub
End Class
備註
分散式垃圾回收負責控制伺服器應用程式的壽命,並在其壽命過期時將其刪除。 傳統上,分散式垃圾回收使用參考計數與 ping 來控制。 當每個物件有少數客戶端時,這種方法運作良好,但當每個物件有數千個客戶端時,效果就不佳。 終身服務可承接傳統分散式垃圾回收器的功能,且隨著客戶數量增加,擴展性良好。
終身服務會與每個遠端啟動的物件綁定租約。 租約到期後,該物件會被移除。
Note
這個類別會產生連結需求。 若直接呼叫者沒有基礎設施權限,則會拋出 SecurityException。 更多資訊請參閱 連結要求 。
建構函式
| 名稱 | Description |
|---|---|
| LifetimeServices() |
已淘汰.
建立 的實例 LifetimeServices。 |
屬性
| 名稱 | Description |
|---|---|
| LeaseManagerPollTime |
取得或設定租約管理員每次啟動之間的時間間隔,以清理過期租約。 |
| LeaseTime |
取得或設定初始租約時間範圍。AppDomain |
| RenewOnCallTime |
每次伺服器物件有呼叫時,取得或設定租約延長的時間。 |
| SponsorshipTimeout |
決定租約經理等待擔保人回來的時間,並設定租約續約時間。 |
方法
| 名稱 | Description |
|---|---|
| Equals(Object) |
判斷指定的物件是否等於目前的物件。 (繼承來源 Object) |
| GetHashCode() |
做為預設哈希函式。 (繼承來源 Object) |
| GetType() |
取得目前實例的 Type。 (繼承來源 Object) |
| MemberwiseClone() |
建立目前 Object的淺層複本。 (繼承來源 Object) |
| ToString() |
傳回表示目前 物件的字串。 (繼承來源 Object) |