クリックして評価とフィードバックをお寄せください
MSDN
MSDN ライブラリ
Visual Studio 2005
Visual Studio ドキュメント
.NET Framework の拡張開発
 方法 : プールされるオブジェクトを作成しサイズ制限とタイムアウト制限...
このページは次のバージョンについて記述しています。
Microsoft Visual Studio 2005/.NET Framework 2.0

その他のバージョンについては、以下の情報を参照してください。
.NET Framework 開発者ガイド
方法 : プールされるオブジェクトを作成しサイズ制限とタイムアウト制限を設定する

System.EnterpriseServices.ServicedComponent クラスから派生したクラスの場合、COM+ オブジェクト プーリングを使用して、オブジェクトを最初からインスタンス化するオーバーヘッドを回避できます。オブジェクトは、アクティブになるとプールから取り出されるためです。詳細については、「オブジェクト プーリング」を参照してください。

プールされるオブジェクトを作成しサイズ制限とタイムアウト制限を設定するには

  1. System.EnterpriseServices.ServicedComponent クラスから派生するクラスを定義し、ObjectPoolingAttribute 属性をそのクラスに適用します。たとえば、次のコードは、TestObjectPooling という名前のクラスを定義し、そのクラスの MinPoolSize プロパティ、MaxPoolSize プロパティ、および CreationTimeout プロパティを設定します。

    Visual Basic
    <ObjectPooling(MinPoolSize := 2, MaxPoolSize := 5, _
    CreationTimeout := 20000)> _
    Public Class TestObjectPooling 
    Inherits ServicedComponent
    End Class 
    

    C#
    [ObjectPooling(Enabled=true, MinPoolSize=2, MaxPoolSize=5, CreationTimeout=20000)]
    public class TestObjectPooling : ServicedComponent
    {
    }
    
  2. System.EnterpriseServices.ServicedComponent クラスの Activate メソッド、Deactivate メソッド、および CanBePooled メソッドをオーバーライドします。

  3. プールされたオブジェクトをクライアント アプリケーションでテストするには、次の手順を実行します。

    1. プールされたオブジェクト クラスのインスタンスを作成し、プールされたオブジェクトのメソッドを呼び出します。たとえば、次のコードは、TestObjectPooling クラスのインスタンスを作成し、Perform メソッドを呼び出します。

      Visual Basic
      Public Class App
          Overloads Public Shared Sub Main(args() As String)
             Dim order As New TestObjectPooling()
                  order.Perform()
                  
      

      C#
      public class App
      {
          public static int Main(string[] args)
          {
             TestObjectPooling order = new TestObjectPooling();
             order.Perform();
            
      
    2. DisposeObject メソッドを呼び出してオブジェクトをプールに返します。

      Visual Basic
      ServicedComponent.DisposeObject (order)
      

      C#
      ServicedComponent.DisposeObject (order);
      

使用例

Visual Basic
<ObjectPooling(MinPoolSize := 2, MaxPoolSize := 5, _
CreationTimeout := 20000)> _
Public Class TestObjectPooling 
Inherits ServicedComponent
      Public Sub Perform ()
            ' Method contents go here.
      End Sub 
      Protected Overrides Sub Activate()
            ' Called when removed from the pool.
      End Sub 
      Protected Overrides Sub Deactivate()
            ' Called before deactivating or placing back in pool.
      End Sub 
      Protected Overrides Function CanBePooled() As Boolean
            ' Called after Deactivate. Indicate your vote here.
            Return True
      End Function 
End Class 
C#
[ObjectPooling(Enabled=true, MinPoolSize=2, MaxPoolSize=5, CreationTimeout=20000)]
public class TestObjectPooling : ServicedComponent
{
      public void Perform ()
      {
         // Method contents go here.
      }
      protected override void Activate()
      {
         // Called when removed from the pool.
      }
      protected override void Deactivate()
      {
         // Called before deactivating or placing back in pool.
      }
      protected override bool CanBePooled()
      {
         // Called after Deactivate. Indicate your vote here.
         return true;
      }
}
 

参照

コミュニティ コンテンツ   コミュニティ コンテンツとは
新しいコンテンツの追加 RSS  注釈
Processing
Page view tracker