LifetimeServices Kelas
Definisi
Penting
Beberapa informasi terkait produk prarilis yang dapat diubah secara signifikan sebelum dirilis. Microsoft tidak memberikan jaminan, tersirat maupun tersurat, sehubungan dengan informasi yang diberikan di sini.
Mengontrol the.NET layanan seumur hidup jarak jauh.
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
- Warisan
-
LifetimeServices
- Atribut
Contoh
#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
Keterangan
Pengumpulan sampah terdistribusi bertanggung jawab untuk mengontrol masa pakai aplikasi server, dan untuk menghapusnya ketika masa pakainya telah kedaluwarsa. Secara tradisional, pengumpulan sampah terdistribusi menggunakan jumlah referensi dan ping untuk kontrol. Ini berfungsi dengan baik ketika ada beberapa klien per objek, tetapi tidak berfungsi dengan baik ketika ada ribuan klien per setiap objek. Layanan seumur hidup dapat mengasumsikan fungsi pengumpul sampah terdistribusi tradisional, dan menskalakan dengan baik ketika jumlah klien meningkat.
Layanan seumur hidup mengaitkan sewa dengan setiap objek yang diaktifkan dari jarak jauh. Ketika sewa kedaluwarsa, objek dihapus.
Catatan
Kelas ini membuat permintaan tautan. SecurityException dilemparkan jika penelepon langsung tidak memiliki izin infrastruktur. Lihat Permintaan Tautan untuk informasi selengkapnya.
Konstruktor
LifetimeServices() |
Kedaluwarsa.
Membuat instans LifetimeServices. |
Properti
LeaseManagerPollTime |
Mendapatkan atau mengatur interval waktu antara setiap aktivasi manajer sewa untuk membersihkan sewa yang kedaluwarsa. |
LeaseTime |
Mendapatkan atau mengatur rentang waktu sewa awal untuk AppDomain. |
RenewOnCallTime |
Mendapatkan atau mengatur jumlah waktu saat sewa diperpanjang setiap kali panggilan masuk pada objek server. |
SponsorshipTimeout |
Mendapatkan atau menetapkan jumlah waktu manajer sewa menunggu sponsor untuk kembali dengan waktu perpanjangan sewa. |
Metode
Equals(Object) |
Menentukan apakah objek yang ditentukan sama dengan objek saat ini. (Diperoleh dari Object) |
GetHashCode() |
Berfungsi sebagai fungsi hash default. (Diperoleh dari Object) |
GetType() |
Mendapatkan instans Type saat ini. (Diperoleh dari Object) |
MemberwiseClone() |
Membuat salinan dangkal dari yang saat ini Object. (Diperoleh dari Object) |
ToString() |
Mengembalikan string yang mewakili objek saat ini. (Diperoleh dari Object) |