ServicedComponent 類別

定義

表示所有使用 COM+ 服務之類別的基底類別。Represents the base class of all classes using COM+ services.

public ref class ServicedComponent abstract : ContextBoundObject, IDisposable, System::EnterpriseServices::IRemoteDispatch, System::EnterpriseServices::IServicedComponentInfo
[System.Serializable]
public abstract class ServicedComponent : ContextBoundObject, IDisposable, System.EnterpriseServices.IRemoteDispatch, System.EnterpriseServices.IServicedComponentInfo
type ServicedComponent = class
    inherit ContextBoundObject
    interface IRemoteDispatch
    interface IDisposable
    interface IServicedComponentInfo
Public MustInherit Class ServicedComponent
Inherits ContextBoundObject
Implements IDisposable, IRemoteDispatch, IServicedComponentInfo
繼承
衍生
屬性
實作

範例

下列程式碼範例示範如何將類別公開為已設定的 COM 元件。The following code example demonstrates how to expose a class as a configured COM component.


[assembly:ApplicationName("Calculator")];
[assembly:ApplicationActivation(ActivationOption::Library)];
[assembly:System::Reflection::AssemblyKeyFile("Calculator.snk")];
public ref class Calculator: public ServicedComponent
{
public:
   int Add( int x, int y )
   {
      return (x + y);
   }

};

using System;
using System.EnterpriseServices;

[assembly: ApplicationName("Calculator")]
[assembly: ApplicationActivation(ActivationOption.Library)]
[assembly: System.Reflection.AssemblyKeyFile("Calculator.snk")]
public class Calculator : ServicedComponent
{
    public int Add (int x, int y)
    {
        return(x+y);
    }
}

若要將此類別部署為已設定的 COM 元件, 您必須產生強式金鑰、將類別編譯為程式庫, 然後註冊程式庫。To deploy this class as a configured COM component, you must generate a strong key, compile the class as a library, and register the library. 這三個步驟是透過下列三個命令來完成。These three steps are accomplished by the following three commands.

sn -k Calculator.snk  
csc /t:library Calculator.cs  
regsvcs Calculator.dll  

備註

在某些情況下, 從ServicedComponent com + 應用程式中執行的衍生類別可能會停止回應。Under certain conditions, a class that is derived from ServicedComponent that runs in a COM+ application may stop responding. 這個問題是由活動鎖死所造成。This problem is caused by an Activity deadlock. 因為元件參考的非同步清除, 所以多執行緒應用程式上的活動可能會鎖死。Activities can deadlock on multithreaded applications because of an asynchronous cleanup of component references. 若要解決這個問題, 請在Dispose您完成使用衍生自ServicedComponent的物件時呼叫方法。To work around this problem, call the Dispose method when you complete work with objects derived from ServicedComponent.

注意

用戶端程式代碼Dispose必須呼叫服務元件上的, 以確保正常運作。Client code must call Dispose on serviced components to ensure proper operation.

建構函式

ServicedComponent()

初始化 ServicedComponent 類別的新執行個體。Initializes a new instance of the ServicedComponent class.

方法

Activate()

從集區建立或配置物件時由基礎結構所呼叫。Called by the infrastructure when the object is created or allocated from a pool. 覆寫這個方法來加入自訂初始化程式碼至物件。Override this method to add custom initialization code to objects.

CanBePooled()

這個方法在物件放回集區內之前為基礎結構所呼叫。This method is called by the infrastructure before the object is put back into the pool. 覆寫這個方法來表決物件是否要放回到集區內。Override this method to vote on whether the object is put back into the pool.

Construct(String)

剛好在傳入建構函式字串並呼叫建構函式之後由基礎結構所呼叫。Called by the infrastructure just after the constructor is called, passing in the constructor string. 覆寫這個方法來利用建構字串值。Override this method to make use of the construction string value.

CreateObjRef(Type)

建立包含所有相關資訊的物件,這些資訊是產生用來與遠端物件通訊的所需 Proxy。Creates an object that contains all the relevant information required to generate a proxy used to communicate with a remote object.

(繼承來源 MarshalByRefObject)
Deactivate()

物件即將停用時由基礎結構所呼叫。Called by the infrastructure when the object is about to be deactivated. 在使用 Just-In-Time (JIT) 編譯的程式碼或物件共用時,可覆寫這個方法來加入自訂最終處理程式碼至物件。Override this method to add custom finalization code to objects when just-in-time (JIT) compiled code or object pooling is used.

Dispose()

釋放 ServicedComponent 所使用的所有資源。Releases all resources used by the ServicedComponent.

Dispose(Boolean)

釋放 ServicedComponent 所使用的 Unmanaged 資源,並選擇性地釋放 Managed 資源。Releases the unmanaged resources used by the ServicedComponent and optionally releases the managed resources.

DisposeObject(ServicedComponent)

結束物件並移除相關 COM+ 參考。Finalizes the object and removes the associated COM+ reference.

Equals(Object)

判斷指定的物件是否等於目前的物件。Determines whether the specified object is equal to the current object.

(繼承來源 Object)
GetHashCode()

做為預設雜湊函式。Serves as the default hash function.

(繼承來源 Object)
GetLifetimeService()

擷取控制這個執行個體存留期 (Lifetime) 原則的目前存留期服務物件。Retrieves the current lifetime service object that controls the lifetime policy for this instance.

(繼承來源 MarshalByRefObject)
GetType()

取得目前執行個體的 TypeGets the Type of the current instance.

(繼承來源 Object)
InitializeLifetimeService()

取得存留期服務物件,以控制這個執行個體的存留期原則。Obtains a lifetime service object to control the lifetime policy for this instance.

(繼承來源 MarshalByRefObject)
MemberwiseClone()

建立目前 Object 的淺層複本 (Shallow Copy)。Creates a shallow copy of the current Object.

(繼承來源 Object)
MemberwiseClone(Boolean)

建立目前 MarshalByRefObject 物件的淺層複本。Creates a shallow copy of the current MarshalByRefObject object.

(繼承來源 MarshalByRefObject)
ToString()

傳回代表目前物件的字串。Returns a string that represents the current object.

(繼承來源 Object)

明確介面實作

IRemoteDispatch.RemoteDispatchAutoDone(String)

確保在 COM+ 內容中,ServicedComponent 類別物件的 done 位元會在 Remote Method Invocation 之後設為 trueEnsures that, in the COM+ context, the ServicedComponent class object's done bit is set to true after a remote method invocation.

IRemoteDispatch.RemoteDispatchNotAutoDone(String)

不能確保在 COM+ 內容中,ServicedComponent 類別物件的 done 位元會在 Remote Method Invocation 之後設為 trueDoes not ensure that, in the COM+ context, the ServicedComponent class object's done bit is set to true after a remote method invocation.

IServicedComponentInfo.GetComponentInfo(Int32, String[])

取得 ServicedComponent 類別執行個體的某些資訊。Obtains certain information about the ServicedComponent class instance.

適用於