ObjectPoolingAttribute 类

定义

启用和配置用于组件的对象池。 此类不能被继承。

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

示例

下面的代码示例演示了此属性的用法。

#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+ 目录中启用,则必须在组件上指定它。

有关 实例 ObjectPoolingAttribute的初始属性值列表, ObjectPoolingAttribute 请参阅 构造函数。

有关使用特性的详细信息,请参阅 特性

构造函数

ObjectPoolingAttribute()

初始化 ObjectPoolingAttribute 类的新实例并将 EnabledMaxPoolSizeMinPoolSizeCreationTimeout 属性设置为其默认值。

ObjectPoolingAttribute(Boolean)

初始化 ObjectPoolingAttribute 类的新实例并设置 Enabled 属性。

ObjectPoolingAttribute(Boolean, Int32, Int32)

初始化 ObjectPoolingAttribute 类的新实例并设置 EnabledMaxPoolSizeMinPoolSize 属性。

ObjectPoolingAttribute(Int32, Int32)

初始化 ObjectPoolingAttribute 类的新实例并设置 MaxPoolSizeMinPoolSize 属性。

属性

CreationTimeout

获取或设置在引发异常前等待对象可用于池中的时间长度。 该值以毫秒为单位。

Enabled

获取或设置一个值,该值指示是否启用对象池。

MaxPoolSize

获取或设置表示池的最大大小的值。

MinPoolSize

获取或设置表示池的最小大小的值。

TypeId

在派生类中实现时,获取此 Attribute 的唯一标识符。

(继承自 Attribute)

方法

AfterSaveChanges(Hashtable)

在 COM+ 目录中安装并配置程序集时,由 .NET Framework 基础结构在内部调用。

Apply(Hashtable)

ObjectPoolingAttribute 类特性应用到某个服务组件时,由 .NET Framework 基础结构在内部调用。

Equals(Object)

返回一个值,该值指示此实例是否与指定的对象相等。

(继承自 Attribute)
GetHashCode()

返回此实例的哈希代码。

(继承自 Attribute)
GetType()

获取当前实例的 Type

(继承自 Object)
IsDefaultAttribute()

在派生类中重写时,指示此实例的值是否是派生类的默认值。

(继承自 Attribute)
IsValidTarget(String)

在 COM+ 目录中安装并配置程序集时,由 .NET Framework 基础结构在内部调用。

Match(Object)

当在派生类中重写时,返回一个指示此实例是否等于指定对象的值。

(继承自 Attribute)
MemberwiseClone()

创建当前 Object 的浅表副本。

(继承自 Object)
ToString()

返回表示当前对象的字符串。

(继承自 Object)

显式接口实现

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

将一组名称映射为对应的一组调度标识符。

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

检索对象的类型信息,然后可以使用该信息获取接口的类型信息。

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

检索对象提供的类型信息接口的数量(0 或 1)。

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

提供对某一对象公开的属性和方法的访问。

(继承自 Attribute)

适用于