Export (0) Print
Expand All

ObjectPoolingAttribute Class

Enables and configures object pooling for a component. This class cannot be inherited.

Namespace: System.EnterpriseServices
Assembly: System.EnterpriseServices (in system.enterpriseservices.dll)

[ComVisibleAttribute(false)] 
[AttributeUsageAttribute(AttributeTargets.Class, Inherited=true)] 
public sealed class ObjectPoolingAttribute : Attribute
/** @attribute ComVisibleAttribute(false) */ 
/** @attribute AttributeUsageAttribute(AttributeTargets.Class, Inherited=true) */ 
public final class ObjectPoolingAttribute extends Attribute
ComVisibleAttribute(false) 
AttributeUsageAttribute(AttributeTargets.Class, Inherited=true) 
public final class ObjectPoolingAttribute extends Attribute
Not applicable.

If object pooling is specified, it must not be disabled in the COM+ catalog; if enabled in the COM+ catalog, it must be specified on the component.

For a list of initial property values for an instance of ObjectPoolingAttribute, see the ObjectPoolingAttribute constructor.

For more information about using attributes, see Extending Metadata Using Attributes.

The following code example demonstrates the use of this attribute.

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

}

import System.*;
import System.EnterpriseServices.*;
import System.Windows.Forms.*;

/** @assembly ApplicationName("ObjectInspector")
 */
/** @assembly ApplicationActivation(ActivationOption.Server)
 */
/** @assembly System.Reflection.AssemblyKeyFile("Inspector.snk")
 */

/** @attribute JustInTimeActivation()
 */
/** @attribute ObjectPooling(MinPoolSize = 2, MaxPoolSize = 100, 
    CreationTimeout = 1000)
 */
public class ObjectInspector extends ServicedComponent
{
    public String IdentifyObject(Object obj)
    {
        // Return this object to the pool after use.
        ContextUtil.set_DeactivateOnReturn(true);
        // Get the supplied object's type.        
        Type objType = obj.GetType();
        // Return its name.
        return objType.get_FullName();
    } //IdentifyObject

    protected void Activate()
    {
        MessageBox.Show(String.Format("Now entering...\nApplication: {0}\n"
            + "Instance: {1}\nContext: {2}\n",
            ContextUtil.get_ApplicationId().ToString(),
            ContextUtil.get_ApplicationInstanceId().ToString(),
            ContextUtil.get_ContextId().ToString()));
    } //Activate

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

    // This object can be pooled.
    protected boolean CanBePooled()
    {
        return true;
    } //CanBePooled
} //ObjectInspector 

System.Object
   System.Attribute
    System.EnterpriseServices.ObjectPoolingAttribute

Any public static (Shared in Visual Basic) members of this type are thread safe. Any instance members are not guaranteed to be thread safe.

Windows 98, Windows Server 2000 SP4, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition

The Microsoft .NET Framework 3.0 is supported on Windows Vista, Microsoft Windows XP SP2, and Windows Server 2003 SP1.

.NET Framework

Supported in: 3.0, 2.0, 1.1, 1.0

Community Additions

ADD
Show:
© 2014 Microsoft