ObjectPoolingAttribute Classe

Definizione

Consente di attivare e configurare il pool di oggetti per un componente. La classe non può essere ereditata.

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
Ereditarietà
ObjectPoolingAttribute
Attributi

Esempio

Nell'esempio di codice seguente viene illustrato l'uso di questo attributo.

#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

Commenti

Se viene specificato il pool di oggetti, non deve essere disabilitato nel catalogo COM+; se abilitato nel catalogo COM+, deve essere specificato nel componente.

Per un elenco dei valori iniziali delle proprietà per un'istanza di ObjectPoolingAttribute, vedere il ObjectPoolingAttribute costruttore .

Per altre informazioni sull'uso degli attributi, vedere Attributi.

Costruttori

ObjectPoolingAttribute()

Consente di inizializzare una nuova istanza della classe ObjectPoolingAttribute e imposta i valori predefiniti delle proprietà Enabled, MaxPoolSize, MinPoolSize e CreationTimeout.

ObjectPoolingAttribute(Boolean)

Inizializza una nuova istanza della classe ObjectPoolingAttribute e imposta la proprietà Enabled.

ObjectPoolingAttribute(Boolean, Int32, Int32)

Consente di inizializzare una nuova istanza della classe ObjectPoolingAttribute e di impostare le proprietà Enabled, MaxPoolSize e MinPoolSize.

ObjectPoolingAttribute(Int32, Int32)

Inizializza una nuova istanza della classe ObjectPoolingAttribute e imposta le proprietà MaxPoolSize e MinPoolSize.

Proprietà

CreationTimeout

Ottiene o imposta il tempo di attesa della disponibilità di un oggetto nel pool prima che venga generata un'eccezione. Il valore è espresso in millisecondi.

Enabled

Ottiene o imposta un valore che indica se è attivato il pool di oggetti.

MaxPoolSize

Ottiene o imposta il valore relativo alla dimensione massima del pool.

MinPoolSize

Ottiene o imposta il valore relativo alla dimensione minima del pool.

TypeId

Quando è implementata in una classe derivata, ottiene un identificatore univoco della classe Attribute.

(Ereditato da Attribute)

Metodi

AfterSaveChanges(Hashtable)

Chiamato internamente dall'infrastruttura .NET Framework durante l'installazione e la configurazione di assembly nel catalogo COM+.

Apply(Hashtable)

Chiamato internamente dall'infrastruttura .NET Framework durante l'applicazione dell'attributo della classe ObjectPoolingAttribute a un componente servito.

Equals(Object)

Restituisce un valore che indica se questa istanza è uguale a un oggetto specificato.

(Ereditato da Attribute)
GetHashCode()

Restituisce il codice hash per l'istanza.

(Ereditato da Attribute)
GetType()

Ottiene l'oggetto Type dell'istanza corrente.

(Ereditato da Object)
IsDefaultAttribute()

In caso di override in una classe derivata, indica se il valore di questa istanza è il valore predefinito per la classe derivata.

(Ereditato da Attribute)
IsValidTarget(String)

Chiamato internamente dall'infrastruttura .NET Framework durante l'installazione e la configurazione di assembly nel catalogo COM+.

Match(Object)

Quando è sottoposto a override in una classe derivata, restituisce un valore che indica se questa istanza equivale a un oggetto specificato.

(Ereditato da Attribute)
MemberwiseClone()

Crea una copia superficiale dell'oggetto Object corrente.

(Ereditato da Object)
ToString()

Restituisce una stringa che rappresenta l'oggetto corrente.

(Ereditato da Object)

Implementazioni dell'interfaccia esplicita

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

Esegue il mapping di un set di nomi a un set corrispondente di ID dispatch.

(Ereditato da Attribute)
_Attribute.GetTypeInfo(UInt32, UInt32, IntPtr)

Recupera le informazioni sul tipo relative a un oggetto, che possono essere usate per ottenere informazioni sul tipo relative a un'interfaccia.

(Ereditato da Attribute)
_Attribute.GetTypeInfoCount(UInt32)

Recupera il numero delle interfacce di informazioni sul tipo fornite da un oggetto (0 o 1).

(Ereditato da Attribute)
_Attribute.Invoke(UInt32, Guid, UInt32, Int16, IntPtr, IntPtr, IntPtr, IntPtr)

Fornisce l'accesso a proprietà e metodi esposti da un oggetto.

(Ereditato da Attribute)

Si applica a