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 代表應用程式啟動時所建立的物件數目,以及應用程式執行時,在集區中維護的物件數目下限。 如果集區中的可用物件數目低於指定的最小值,則會建立新的 物件,以符合任何未處理的物件要求並重新填入集區。 如果集區中可用的物件數目大於最小數目,則會在清除週期期間終結這些剩餘物件。