語言

ContextUtil 類別

定義

取得 COM+ 物件上下文的資訊。 此類別無法獲得繼承。

public ref class ContextUtil sealed
public sealed class ContextUtil
type ContextUtil = class
Public NotInheritable Class ContextUtil
繼承
ContextUtil

範例

以下程式碼範例示範如何使用 ContextUtil 建立交易式 ServicedComponent。


[assembly:System::Reflection::AssemblyKeyFile("Transaction.snk")];
[Transaction]
public ref class TransactionalComponent: public ServicedComponent
{
public:
   void TransactionalMethod( String^ data )
   {
      ContextUtil::DeactivateOnReturn = true;
      ContextUtil::MyTransactionVote = TransactionVote::Abort;
      
      // do work with data
      ContextUtil::MyTransactionVote = TransactionVote::Commit;
   }

};
[Transaction]
public class TransactionalComponent : ServicedComponent
{

    public void TransactionalMethod (string data)
    {

      ContextUtil.DeactivateOnReturn = true;
      ContextUtil.MyTransactionVote = TransactionVote.Abort;

      // Do work with data. Return if any errors occur.

      // Vote to commit. If any errors occur, this code will not execute.
      ContextUtil.MyTransactionVote = TransactionVote.Commit;
    }
}
<Transaction()>  _
Public Class TransactionalComponent
    Inherits ServicedComponent
    
    
    Public Sub TransactionalMethod(ByVal data As String) 
        
        ContextUtil.DeactivateOnReturn = True
        ContextUtil.MyTransactionVote = TransactionVote.Abort
        
        ' Do work with data. Return if any errors occur.
        ' Vote to commit. If any errors occur, this code will not execute.
        ContextUtil.MyTransactionVote = TransactionVote.Commit
    
    End Sub
End Class

備註

ContextUtil 是取得 COM+ 上下文資訊的首選類別。 由於此類別的成員皆為 static(Visual Basic 中為 shared),因此使用前無需實例化。

屬性

名稱 Description
ActivityId

會取得一個 GUID,代表包含該元件的活動。

ApplicationId

會為目前應用程式取得 GUID。

ApplicationInstanceId

會取得目前應用程式實例的 GUID。

ContextId

會拿到一個針對當前情境的 GUID。

DeactivateOnReturn

在 COM+ 上下文中取得或設定該 done 位元。

IsInTransaction

會得到一個值,表示目前情境是否為交易型。

IsSecurityEnabled

會獲得一個值,表示角色基礎安全在當前情境中是否有效。

MyTransactionVote

在 COM+ 上下文中取得或設定該 consistent 位元。

PartitionId

會拿到目前分割區的 GUID。

SystemTransaction

取得目前的交易上下文。

Transaction

取得一個描述當前 COM+ DTC 交易的物件。

TransactionId

取得目前 COM+ DTC 交易的 GUID。

方法

名稱 Description
DisableCommit()

在 COM+ 上下文中,將位consistent元與done位元都設為 。false

EnableCommit()

在 COM+ 情境中,將位元設consistent為 ,true位done元為 。false

Equals(Object)

判斷指定的物件是否等於目前的物件。

(繼承來源 Object)
GetHashCode()

做為預設哈希函式。

(繼承來源 Object)
GetNamedProperty(String)

從 COM+ 上下文回傳一個命名屬性。

GetType()

取得目前實例的 Type。

(繼承來源 Object)
IsCallerInRole(String)

判斷呼叫者是否處於指定角色。

IsDefaultContext()

判斷被服務元件是否在預設情境下被啟用。 沒有 COM+ 目錄資訊的服務元件會在預設情境中被啟用。

MemberwiseClone()

建立目前 Object的淺層複本。

(繼承來源 Object)
SetAbort()

在 COM+ 情境中,將位元設consistent為 ,false位done元為 。true

SetComplete()

在 COM+ 上下文中,將位元consistent和位元設定done為 。true

SetNamedProperty(String, Object)

為 COM+ 上下文設定命名屬性。

ToString()

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

(繼承來源 Object)

適用於