ObjectPoolingAttribute Constructeurs

Définition

Initialise une nouvelle instance de la classe ObjectPoolingAttribute.

Surcharges

Nom Description
ObjectPoolingAttribute()

Initialise une nouvelle instance de la ObjectPoolingAttribute classe et définit les Enabledpropriétés , MaxPoolSizeet MinPoolSizeCreationTimeout les propriétés sur leurs valeurs par défaut.

ObjectPoolingAttribute(Boolean)

Initialise une nouvelle instance de la ObjectPoolingAttribute classe et définit la Enabled propriété.

ObjectPoolingAttribute(Int32, Int32)

Initialise une nouvelle instance de la ObjectPoolingAttribute classe et définit les propriétés et MaxPoolSize les MinPoolSize propriétés.

ObjectPoolingAttribute(Boolean, Int32, Int32)

Initialise une nouvelle instance de la ObjectPoolingAttribute classe et définit les propriétés et EnabledMaxPoolSize les MinPoolSizepropriétés.

ObjectPoolingAttribute()

Initialise une nouvelle instance de la ObjectPoolingAttribute classe et définit les Enabledpropriétés , MaxPoolSizeet MinPoolSizeCreationTimeout les propriétés sur leurs valeurs par défaut.

public:
 ObjectPoolingAttribute();
public ObjectPoolingAttribute();
Public Sub New ()

Exemples

L’exemple de code suivant illustre l’utilisation de cet attribut.

#using <System.Windows.Forms.dll>
#using <System.Transactions.dll>
#using <System.EnterpriseServices.dll>

using namespace System;
using namespace System::EnterpriseServices;
using namespace System::Windows::Forms;


[assembly:ApplicationName("ObjectInspector")];
[assembly:ApplicationActivation(ActivationOption::Server)];
[assembly:System::Reflection::AssemblyKeyFile("Inspector.snk")];
[JustInTimeActivation]
[ObjectPooling(MinPoolSize=2,MaxPoolSize=100,CreationTimeout=1000)]
public ref class ObjectInspector: public ServicedComponent
{
public:
   String^ IdentifyObject( Object^ obj )
   {
      // Return this object to the pool after use.
      ContextUtil::DeactivateOnReturn = true;

      // Get the supplied object's type.        
      Type^ objType = obj->GetType();

      // Return its name.
      return (objType->FullName);
   }

protected:
   virtual void Activate() override
   {
      MessageBox::Show( String::Format( "Now entering...\nApplication: {0}\nInstance: {1}\nContext: {2}\n", ContextUtil::ApplicationId.ToString(), ContextUtil::ApplicationInstanceId.ToString(), ContextUtil::ContextId.ToString() ) );
   }

   virtual void Deactivate() override
   {
      MessageBox::Show( "Bye Bye!" );
   }

   // This object can be pooled.
   virtual bool CanBePooled() override
   {
      return (true);
   }
};
using System;
using System.EnterpriseServices;
using System.Windows.Forms;

[assembly: ApplicationName("ObjectInspector")]
[assembly: ApplicationActivation(ActivationOption.Server)]
[assembly: System.Reflection.AssemblyKeyFile("Inspector.snk")]

[JustInTimeActivation]
[ObjectPooling(MinPoolSize=2, MaxPoolSize=100, CreationTimeout=1000)]
public class ObjectInspector : ServicedComponent
{

    public string IdentifyObject (Object obj)
    {
        // Return this object to the pool after use.
        ContextUtil.DeactivateOnReturn = true;

        // Get the supplied object's type.
        Type objType = obj.GetType();

        // Return its name.
        return(objType.FullName);
    }

    protected override void Activate()
    {
        MessageBox.Show( String.Format("Now entering...\nApplication: {0}\nInstance: {1}\nContext: {2}\n",
                                       ContextUtil.ApplicationId.ToString(), ContextUtil.ApplicationInstanceId.ToString(),
                                       ContextUtil.ContextId.ToString() ) );
    }

    protected override void Deactivate()
    {
        MessageBox.Show("Bye Bye!");
    }

    // This object can be pooled.
    protected override bool CanBePooled()
    {
        return(true);
    }
}
Imports System.EnterpriseServices
Imports System.Windows.Forms



<Assembly: ApplicationName("ObjectInspector")> 
<Assembly: ApplicationActivation(ActivationOption.Server)> 
<Assembly: System.Reflection.AssemblyKeyFile("Inspector.snk")> 
 
<JustInTimeActivation(), ObjectPooling(MinPoolSize := 2, MaxPoolSize := 100, CreationTimeout := 1000)>  _
Public Class ObjectInspector
    Inherits ServicedComponent
    
    
    Public Function IdentifyObject(ByVal obj As [Object]) As String 
        ' Return this object to the pool after use.
        ContextUtil.DeactivateOnReturn = True
        
        ' Get the supplied object's type.        
        Dim objType As Type = obj.GetType()
        
        ' Return its name.
        Return objType.FullName
    
    End Function 'IdentifyObject

    Protected Overrides Sub Activate() 
        MessageBox.Show(String.Format("Now entering..." + vbLf + "Application: {0}" + vbLf + "Instance: {1}" + vbLf + "Context: {2}" + vbLf, ContextUtil.ApplicationId.ToString(), ContextUtil.ApplicationInstanceId.ToString(), ContextUtil.ContextId.ToString()))
    
    End Sub

    Protected Overrides Sub Deactivate() 
        MessageBox.Show("Bye Bye!")
    
    End Sub

    ' This object can be pooled.
    Protected Overrides Function CanBePooled() As Boolean 
        Return True
    
    End Function 'CanBePooled

End Class

Remarques

Le tableau suivant présente les valeurs de propriété initiales d’une instance de ObjectPoolingAttribute.

Propriété Valeur
Activé true
MaxPoolSize -1
MinPoolSize -1
CreationTimeout -1

S’applique à

ObjectPoolingAttribute(Boolean)

Initialise une nouvelle instance de la ObjectPoolingAttribute classe et définit la Enabled propriété.

public:
 ObjectPoolingAttribute(bool enable);
public ObjectPoolingAttribute(bool enable);
new System.EnterpriseServices.ObjectPoolingAttribute : bool -> System.EnterpriseServices.ObjectPoolingAttribute
Public Sub New (enable As Boolean)

Paramètres

enable
Boolean

true pour activer le regroupement d’objets ; sinon, false.

Exemples

L’exemple de code suivant crée un nouveau ObjectPoolingAttribute.

[ObjectPooling(true)]
public ref class ObjectPoolingAttributeCtorBool : public ServicedComponent
{
};
[ObjectPooling(true)]
public class ObjectPoolingAttribute_Ctor_Bool : ServicedComponent
{
}
<ObjectPooling(True)>  _
Public Class ObjectPoolingAttribute_Ctor_Bool
    Inherits ServicedComponent
End Class

S’applique à

ObjectPoolingAttribute(Int32, Int32)

Initialise une nouvelle instance de la ObjectPoolingAttribute classe et définit les propriétés et MaxPoolSize les MinPoolSize propriétés.

public:
 ObjectPoolingAttribute(int minPoolSize, int maxPoolSize);
public ObjectPoolingAttribute(int minPoolSize, int maxPoolSize);
new System.EnterpriseServices.ObjectPoolingAttribute : int * int -> System.EnterpriseServices.ObjectPoolingAttribute
Public Sub New (minPoolSize As Integer, maxPoolSize As Integer)

Paramètres

minPoolSize
Int32

Taille minimale du pool.

maxPoolSize
Int32

Taille maximale du pool.

Exemples

L’exemple de code suivant crée un nouveau ObjectPoolingAttribute.

[ObjectPooling(1, 10)]
public ref class ObjectPoolingAttributeCtorIntInt : public ServicedComponent
{
};
[ObjectPooling(1, 10)]
public class ObjectPoolingAttribute_Ctor_Int_Int : ServicedComponent
{
}
<ObjectPooling(1, 10)>  _
Public Class ObjectPoolingAttribute_Ctor_Int_Int
    Inherits ServicedComponent
End Class

S’applique à

ObjectPoolingAttribute(Boolean, Int32, Int32)

Initialise une nouvelle instance de la ObjectPoolingAttribute classe et définit les propriétés et EnabledMaxPoolSize les MinPoolSizepropriétés.

public:
 ObjectPoolingAttribute(bool enable, int minPoolSize, int maxPoolSize);
public ObjectPoolingAttribute(bool enable, int minPoolSize, int maxPoolSize);
new System.EnterpriseServices.ObjectPoolingAttribute : bool * int * int -> System.EnterpriseServices.ObjectPoolingAttribute
Public Sub New (enable As Boolean, minPoolSize As Integer, maxPoolSize As Integer)

Paramètres

enable
Boolean

true pour activer le regroupement d’objets ; sinon, false.

minPoolSize
Int32

Taille minimale du pool.

maxPoolSize
Int32

Taille maximale du pool.

Exemples

L’exemple de code suivant crée un nouveau ObjectPoolingAttribute.

[ObjectPooling(true, 1, 10)]
public ref class ObjectPoolingAttributeCtorBoolIntInt : 
    public ServicedComponent
{
};
[ObjectPooling(true, 1, 10)]
public class ObjectPoolingAttribute_Ctor_Bool_Int_Int : ServicedComponent
{
}
<ObjectPooling(True, 1, 10)>  _
Public Class ObjectPoolingAttribute_Ctor_Bool_Int_Int
    Inherits ServicedComponent
End Class

S’applique à