ObjectPoolingAttribute.MinPoolSize 属性
定义
重要
一些信息与预发行产品相关,相应产品在发行之前可能会进行重大修改。 对于此处提供的信息,Microsoft 不作任何明示或暗示的担保。
获取或设置表示池的最小大小的值。
public:
property int MinPoolSize { int get(); void set(int value); };
public int MinPoolSize { get; set; }
member this.MinPoolSize : int with get, set
Public Property MinPoolSize As Integer
属性值
池中对象的最小数目。
示例
下面的代码示例演示如何使用此属性。
[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);
}
};
[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);
}
}
<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
注解
MinPoolSize 表示应用程序启动时创建的对象数,以及应用程序运行时在池中维护的最小对象数。 如果池中的可用对象数低于指定的最小值,则会创建新对象以满足任何未完成的对象请求并重新填充池。 如果池中的可用对象数大于最小数量,则会在清理周期期间销毁这些剩余对象。