ObjectPoolingAttribute 类

定义

启用和配置用于组件的对象池。Enables and configures object pooling for a component. 此类不能被继承。This class cannot be inherited.

public ref class ObjectPoolingAttribute sealed : Attribute
[System.AttributeUsage(System.AttributeTargets.Class, Inherited=true)]
[System.Runtime.InteropServices.ComVisible(false)]
public sealed class ObjectPoolingAttribute : Attribute
type ObjectPoolingAttribute = class
    inherit Attribute
Public NotInheritable Class ObjectPoolingAttribute
Inherits Attribute
继承
ObjectPoolingAttribute
属性

示例

下面的代码示例演示如何使用此特性。The following code example demonstrates the use of this attribute.

#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

注解

如果指定对象池, 则不能在 COM + 目录中禁用它;如果在 COM + 目录中启用, 则必须在组件上指定它。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.

有关实例ObjectPoolingAttribute的初始属性值的列表, ObjectPoolingAttribute请参见构造函数。For a list of initial property values for an instance of ObjectPoolingAttribute, see the ObjectPoolingAttribute constructor.

有关使用特性的详细信息, 请参阅特性For more information about using attributes, see Attributes.

构造函数

ObjectPoolingAttribute()

初始化 ObjectPoolingAttribute 类的新实例并将 EnabledMaxPoolSizeMinPoolSizeCreationTimeout 属性设置为其默认值。Initializes a new instance of the ObjectPoolingAttribute class and sets the Enabled, MaxPoolSize, MinPoolSize, and CreationTimeout properties to their default values.

ObjectPoolingAttribute(Boolean)

初始化 ObjectPoolingAttribute 类的新实例并设置 Enabled 属性。Initializes a new instance of the ObjectPoolingAttribute class and sets the Enabled property.

ObjectPoolingAttribute(Boolean, Int32, Int32)

初始化 ObjectPoolingAttribute 类的新实例并设置 EnabledMaxPoolSizeMinPoolSize 属性。Initializes a new instance of the ObjectPoolingAttribute class and sets the Enabled, MaxPoolSize, and MinPoolSize properties.

ObjectPoolingAttribute(Int32, Int32)

初始化 ObjectPoolingAttribute 类的新实例并设置 MaxPoolSizeMinPoolSize 属性。Initializes a new instance of the ObjectPoolingAttribute class and sets the MaxPoolSize and MinPoolSize properties.

属性

CreationTimeout

获取或设置在引发异常前等待对象可用于池中的时间长度。Gets or sets the length of time to wait for an object to become available in the pool before throwing an exception. 该值以毫秒为单位。This value is in milliseconds.

Enabled

获取或设置一个值,该值指示是否启用对象池。Gets or sets a value that indicates whether object pooling is enabled.

MaxPoolSize

获取或设置表示池的最大大小的值。Gets or sets the value for the maximum size of the pool.

MinPoolSize

获取或设置表示池的最小大小的值。Gets or sets the value for the minimum size of the pool.

TypeId

在派生类中实现时,获取此 Attribute 的唯一标识符。When implemented in a derived class, gets a unique identifier for this Attribute.

(继承自 Attribute)

方法

AfterSaveChanges(Hashtable)

在 COM+ 目录中安装并配置程序集时,由 .NET Framework 基础结构在内部调用。Called internally by the .NET Framework infrastructure while installing and configuring assemblies in the COM+ catalog.

Apply(Hashtable)

ObjectPoolingAttribute 类特性应用到某个服务组件时,由 .NET Framework 基础结构在内部调用。Called internally by the .NET Framework infrastructure while applying the ObjectPoolingAttribute class attribute to a serviced component.

Equals(Object)

返回一个值,该值指示此实例是否与指定的对象相等。Returns a value that indicates whether this instance is equal to a specified object.

(继承自 Attribute)
GetHashCode()

返回此实例的哈希代码。Returns the hash code for this instance.

(继承自 Attribute)
GetType()

获取当前实例的 TypeGets the Type of the current instance.

(继承自 Object)
IsDefaultAttribute()

在派生类中重写时,指示此实例的值是否是派生类的默认值。When overridden in a derived class, indicates whether the value of this instance is the default value for the derived class.

(继承自 Attribute)
IsValidTarget(String)

在 COM+ 目录中安装并配置程序集时,由 .NET Framework 基础结构在内部调用。Called internally by the .NET Framework infrastructure while installing and configuring assemblies in the COM+ catalog.

Match(Object)

当在派生类中重写时,返回一个指示此实例是否等于指定对象的值。When overridden in a derived class, returns a value that indicates whether this instance equals a specified object.

(继承自 Attribute)
MemberwiseClone()

创建当前 Object 的浅表副本。Creates a shallow copy of the current Object.

(继承自 Object)
ToString()

返回表示当前对象的字符串。Returns a string that represents the current object.

(继承自 Object)

显式接口实现

_Attribute.GetIDsOfNames(Guid, IntPtr, UInt32, UInt32, IntPtr)

将一组名称映射为对应的一组调度标识符。Maps a set of names to a corresponding set of dispatch identifiers.

(继承自 Attribute)
_Attribute.GetTypeInfo(UInt32, UInt32, IntPtr)

检索对象的类型信息,然后可以使用该信息获取接口的类型信息。Retrieves the type information for an object, which can be used to get the type information for an interface.

(继承自 Attribute)
_Attribute.GetTypeInfoCount(UInt32)

检索对象提供的类型信息接口的数量(0 或 1)。Retrieves the number of type information interfaces that an object provides (either 0 or 1).

(继承自 Attribute)
_Attribute.Invoke(UInt32, Guid, UInt32, Int16, IntPtr, IntPtr, IntPtr, IntPtr)

提供对某一对象公开的属性和方法的访问。Provides access to properties and methods exposed by an object.

(继承自 Attribute)

适用于