ObjectPoolingAttribute Constructors

Definition

Initializes a new instance of the ObjectPoolingAttribute class.

Overloads

ObjectPoolingAttribute()

Initializes a new instance of the ObjectPoolingAttribute class and sets the Enabled, MaxPoolSize, MinPoolSize, and CreationTimeout properties to their default values.

ObjectPoolingAttribute(Boolean)

Initializes a new instance of the ObjectPoolingAttribute class and sets the Enabled property.

ObjectPoolingAttribute(Int32, Int32)

Initializes a new instance of the ObjectPoolingAttribute class and sets the MaxPoolSize and MinPoolSize properties.

ObjectPoolingAttribute(Boolean, Int32, Int32)

Initializes a new instance of the ObjectPoolingAttribute class and sets the Enabled, MaxPoolSize, and MinPoolSize properties.

ObjectPoolingAttribute()

Initializes a new instance of the ObjectPoolingAttribute class and sets the Enabled, MaxPoolSize, MinPoolSize, and CreationTimeout properties to their default values.

C#
public ObjectPoolingAttribute();

Examples

The following code example demonstrates the use of this attribute.

C#
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);
    }
}

Remarks

The following table shows initial property values for an instance of ObjectPoolingAttribute.

Property Value
Enabled true
MaxPoolSize -1
MinPoolSize -1
CreationTimeout -1

Applies to

.NET Framework 4.8.1 and other versions
Product Versions
.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

ObjectPoolingAttribute(Boolean)

Initializes a new instance of the ObjectPoolingAttribute class and sets the Enabled property.

C#
public ObjectPoolingAttribute(bool enable);

Parameters

enable
Boolean

true to enable object pooling; otherwise, false.

Examples

The following code example creates a new ObjectPoolingAttribute.

C#
[ObjectPooling(true)]
public class ObjectPoolingAttribute_Ctor_Bool : ServicedComponent
{
}

Applies to

.NET Framework 4.8.1 and other versions
Product Versions
.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

ObjectPoolingAttribute(Int32, Int32)

Initializes a new instance of the ObjectPoolingAttribute class and sets the MaxPoolSize and MinPoolSize properties.

C#
public ObjectPoolingAttribute(int minPoolSize, int maxPoolSize);

Parameters

minPoolSize
Int32

The minimum pool size.

maxPoolSize
Int32

The maximum pool size.

Examples

The following code example creates a new ObjectPoolingAttribute.

C#
[ObjectPooling(1, 10)]
public class ObjectPoolingAttribute_Ctor_Int_Int : ServicedComponent
{
}

Applies to

.NET Framework 4.8.1 and other versions
Product Versions
.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

ObjectPoolingAttribute(Boolean, Int32, Int32)

Initializes a new instance of the ObjectPoolingAttribute class and sets the Enabled, MaxPoolSize, and MinPoolSize properties.

C#
public ObjectPoolingAttribute(bool enable, int minPoolSize, int maxPoolSize);

Parameters

enable
Boolean

true to enable object pooling; otherwise, false.

minPoolSize
Int32

The minimum pool size.

maxPoolSize
Int32

The maximum pool size.

Examples

The following code example creates a new ObjectPoolingAttribute.

C#
[ObjectPooling(true, 1, 10)]
public class ObjectPoolingAttribute_Ctor_Bool_Int_Int : ServicedComponent
{
}

Applies to

.NET Framework 4.8.1 and other versions
Product Versions
.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