Lire en anglais Modifier

Partager via


MarshalByRefObject.InitializeLifetimeService Method

Definition

Important

Some information relates to prerelease product that may be substantially modified before it’s released. Microsoft makes no warranties, express or implied, with respect to the information provided here.

Caution

This Remoting API is not supported and throws PlatformNotSupportedException.

Obtains a lifetime service object to control the lifetime policy for this instance.

C#
[System.Obsolete("This Remoting API is not supported and throws PlatformNotSupportedException.", DiagnosticId="SYSLIB0010", UrlFormat="https://aka.ms/dotnet-warnings/{0}")]
public virtual object InitializeLifetimeService();
C#
public virtual object InitializeLifetimeService();
C#
[System.Security.SecurityCritical]
public virtual object InitializeLifetimeService();

Returns

An object of type ILease used to control the lifetime policy for this instance. This is the current lifetime service object for this instance if one exists; otherwise, a new lifetime service object initialized to the value of the LeaseManagerPollTime property.

Attributes

Exceptions

The immediate caller does not have infrastructure permission.

.NET Core and .NET 5+ only: In all cases.

Examples

The following code example demonstrates creating a lease.

C#
public class MyClass : MarshalByRefObject
{
  public override Object InitializeLifetimeService()
  {
    ILease lease = (ILease)base.InitializeLifetimeService();
    if (lease.CurrentState == LeaseState.Initial)
    {
         lease.InitialLeaseTime = TimeSpan.FromMinutes(1);
         lease.SponsorshipTimeout = TimeSpan.FromMinutes(2);
          lease.RenewOnCallTime = TimeSpan.FromSeconds(2);
    }
      return lease;
  }
}

Remarks

This method is marked obsolete starting in .NET 5.

For more information about lifetime services, see the LifetimeServices class.

Applies to

Produit Versions (Obsolète)
.NET Core 2.0, Core 2.1, Core 2.2, Core 3.0, Core 3.1 (5, 6, 7, 8, 9, 10)
.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
.NET Standard 2.0, 2.1