次の方法で共有


MarshalByRefObject.InitializeLifetimeService メソッド

定義

注意事項

This Remoting API is not supported and throws PlatformNotSupportedException.

このインスタンスの有効期間ポリシーを制御する有効期間サービス オブジェクトを取得します。

public:
 virtual System::Object ^ InitializeLifetimeService();
[System.Obsolete("This Remoting API is not supported and throws PlatformNotSupportedException.", DiagnosticId="SYSLIB0010", UrlFormat="https://aka.ms/dotnet-warnings/{0}")]
public virtual object InitializeLifetimeService ();
public virtual object InitializeLifetimeService ();
[System.Security.SecurityCritical]
public virtual object InitializeLifetimeService ();
[<System.Obsolete("This Remoting API is not supported and throws PlatformNotSupportedException.", DiagnosticId="SYSLIB0010", UrlFormat="https://aka.ms/dotnet-warnings/{0}")>]
abstract member InitializeLifetimeService : unit -> obj
override this.InitializeLifetimeService : unit -> obj
abstract member InitializeLifetimeService : unit -> obj
override this.InitializeLifetimeService : unit -> obj
[<System.Security.SecurityCritical>]
abstract member InitializeLifetimeService : unit -> obj
override this.InitializeLifetimeService : unit -> obj
Public Overridable Function InitializeLifetimeService () As Object

戻り値

Object

対象のインスタンスの有効期間ポリシーを制御するときに使用する、ILease 型のオブジェクト。 存在する場合は、このインスタンスの現在の有効期間サービス オブジェクトです。それ以外の場合は、LeaseManagerPollTime プロパティの値に初期化された新しい有効期間サービス オブジェクトです。

属性

例外

直前の呼び出し元に、インフラストラクチャ アクセス許可がありません。

.NET Core および .NET 5 以降のみ:すべての場合。

リースを作成するコード例を次に示します。

public ref class MyClass: public MarshalByRefObject
{
public:
   
   [System::Security::Permissions::SecurityPermissionAttribute
   (System::Security::Permissions::SecurityAction::Demand,
   Flags=System::Security::Permissions::SecurityPermissionFlag::Infrastructure)]
   virtual Object^ InitializeLifetimeService() override
   {
      ILease^ lease = dynamic_cast<ILease^>(MarshalByRefObject::InitializeLifetimeService());
      if ( lease->CurrentState == LeaseState::Initial )
      {
         lease->InitialLeaseTime = TimeSpan::FromMinutes( 1 );
         lease->SponsorshipTimeout = TimeSpan::FromMinutes( 2 );
         lease->RenewOnCallTime = TimeSpan::FromSeconds( 2 );
      }

      return lease;
   }

};
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;
  }
}
type MyClass() =
    inherit MarshalByRefObject()
   
    override _.InitializeLifetimeService() =
        let lease = base.InitializeLifetimeService() :?> ILease
        if lease.CurrentState = LeaseState.Initial then
            lease.InitialLeaseTime <- TimeSpan.FromMinutes 1
            lease.SponsorshipTimeout <- TimeSpan.FromMinutes 2
            lease.RenewOnCallTime <- TimeSpan.FromSeconds 2
        lease
Public Class LSClass
    Inherits MarshalByRefObject
    
    <SecurityPermissionAttribute(SecurityAction.Demand, _
                                 Flags:=SecurityPermissionFlag.Infrastructure)> _
    Public Overrides Function InitializeLifetimeService() As Object
        Dim lease As ILease = CType(MyBase.InitializeLifetimeService(), ILease)
        If lease.CurrentState = LeaseState.Initial Then
            lease.InitialLeaseTime = TimeSpan.FromMinutes(1)
            lease.SponsorshipTimeout = TimeSpan.FromMinutes(2)
            lease.RenewOnCallTime = TimeSpan.FromSeconds(2)
        End If
        Return lease
    End Function


    Public Shared Sub Main()  
    ' The main thread processing is here.
    End Sub
End Class

注釈

このメソッドは、.NET 5 以降では廃止されたとマークされています。

有効期間サービスの詳細については、クラスを LifetimeServices 参照してください。

適用対象