MarshalByRefObject.InitializeLifetimeService メソッド

定義

このインスタンスの有効期間ポリシーを制御する有効期間サービス オブジェクトを取得します。Obtains a lifetime service object to control the lifetime policy for this instance.

public:
 virtual System::Object ^ InitializeLifetimeService();
[System.Security.SecurityCritical]
public virtual object InitializeLifetimeService ();
abstract member InitializeLifetimeService : unit -> obj
override this.InitializeLifetimeService : unit -> obj
Public Overridable Function InitializeLifetimeService () As Object

戻り値

対象のインスタンスの有効期間ポリシーを制御するときに使用する、ILease 型のオブジェクト。An object of type ILease used to control the lifetime policy for this instance. 存在する場合は、このインスタンスの現在の有効期間サービス オブジェクトです。それ以外の場合は、LeaseManagerPollTime プロパティの値に初期化された新しい有効期間サービス オブジェクトです。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.

属性

例外

直前の呼び出し元に、インフラストラクチャ アクセス許可がありません。The immediate caller does not have infrastructure permission.

リースを作成するコード例を次に示します。The following code example demonstrates creating a lease.

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
{
  [SecurityPermissionAttribute(SecurityAction.Demand, 
                               Flags=SecurityPermissionFlag.Infrastructure)]
  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;
  }
}
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

注釈

有効期間サービスの詳細についてはLifetimeServices 、クラスを参照してください。For more information about lifetime services, see the LifetimeServices class.

セキュリティ

SecurityCriticalAttribute
直前の呼び出し元に完全信頼が必要です。requires full trust for the immediate caller. このメンバーは、部分的に信頼されているコードまたは透過的なコードでは使用できません。This member cannot be used by partially trusted or transparent code.

適用対象