JustInTimeActivationAttribute 類別

定義

開啟或關閉 Just-In-Time (JIT) 啟動過程。 此類別無法獲得繼承。

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

範例

下列程式碼範例示範此屬性的使用方式。

#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

備註

如果指定 JIT 啟用,則不得在 COM+ 目錄中停用它,反之亦然。 如果在 COM+ 目錄中啟用,則必須在元件上指定它。

JIT 啟用預設會針對 COM+ 中設定的元件關閉,但如果要求自動交易,就會自動啟用。

如需使用屬性的詳細資訊,請參閱 屬性

建構函式

JustInTimeActivationAttribute()

初始化 JustInTimeActivationAttribute 類別的新執行個體。 無參數建構函式會啟用 Just-In-Time (JIT) 啟用。

JustInTimeActivationAttribute(Boolean)

false 當做參數傳遞來選擇性允許 Just-In-Time (JIT) 啟動過程的停用,初始化 JustInTimeActivationAttribute 類別的新執行個體。

屬性

TypeId

在衍生類別中實作時,取得這個 Attribute 的唯一識別碼。

(繼承來源 Attribute)
Value

取得 JustInTimeActivationAttribute 設定的值。

方法

Equals(Object)

傳回值,這個值指出此執行個體是否與指定的物件相等。

(繼承來源 Attribute)
GetHashCode()

傳回這個執行個體的雜湊碼。

(繼承來源 Attribute)
GetType()

取得目前執行個體的 Type

(繼承來源 Object)
IsDefaultAttribute()

在衍生類別中覆寫時,表示這個執行個體的值是衍生類別的預設值。

(繼承來源 Attribute)
Match(Object)

在衍生類別中覆寫時,會傳回值,表示這個執行個體是否等於指定物件。

(繼承來源 Attribute)
MemberwiseClone()

建立目前 Object 的淺層複製。

(繼承來源 Object)
ToString()

傳回代表目前物件的字串。

(繼承來源 Object)

明確介面實作

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

將一組名稱對應至一組對應的分派識別項 (Dispatch Identifier)。

(繼承來源 Attribute)
_Attribute.GetTypeInfo(UInt32, UInt32, IntPtr)

擷取物件的類型資訊,可以用來取得介面的類型資訊。

(繼承來源 Attribute)
_Attribute.GetTypeInfoCount(UInt32)

擷取物件提供的類型資訊介面數目 (0 或 1)。

(繼承來源 Attribute)
_Attribute.Invoke(UInt32, Guid, UInt32, Int16, IntPtr, IntPtr, IntPtr, IntPtr)

提供物件所公開的屬性和方法的存取權。

(繼承來源 Attribute)

適用於