ServicedComponent ServicedComponent ServicedComponent ServicedComponent Class

定義

表示所有使用 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 元件公開 (expose)。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方法,當您完成使用物件衍生自ServicedComponentTo work around this problem, call the Dispose method when you complete work with objects derived from ServicedComponent.

注意

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

建構函式

ServicedComponent() ServicedComponent() ServicedComponent() ServicedComponent()

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

方法

Activate() Activate() Activate() 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() CanBePooled() CanBePooled() 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) Construct(String) Construct(String) 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) CreateObjRef(Type) CreateObjRef(Type) CreateObjRef(Type)

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

(Inherited from MarshalByRefObject)
Deactivate() Deactivate() Deactivate() 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() Dispose() Dispose() Dispose()

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

Dispose(Boolean) Dispose(Boolean) Dispose(Boolean) Dispose(Boolean)

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

DisposeObject(ServicedComponent) DisposeObject(ServicedComponent) DisposeObject(ServicedComponent) DisposeObject(ServicedComponent)

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

Equals(Object) Equals(Object) Equals(Object) Equals(Object)

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

(Inherited from Object)
GetHashCode() GetHashCode() GetHashCode() GetHashCode()

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

(Inherited from Object)
GetLifetimeService() GetLifetimeService() GetLifetimeService() GetLifetimeService()

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

(Inherited from MarshalByRefObject)
GetType() GetType() GetType() GetType()

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

(Inherited from Object)
InitializeLifetimeService() InitializeLifetimeService() InitializeLifetimeService() InitializeLifetimeService()

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

(Inherited from MarshalByRefObject)
MemberwiseClone() MemberwiseClone() MemberwiseClone() MemberwiseClone()

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

(Inherited from Object)
MemberwiseClone(Boolean) MemberwiseClone(Boolean) MemberwiseClone(Boolean) MemberwiseClone(Boolean)

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

(Inherited from MarshalByRefObject)
ToString() ToString() ToString() ToString()

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

(Inherited from Object)

明確介面實作

IRemoteDispatch.RemoteDispatchAutoDone(String) IRemoteDispatch.RemoteDispatchAutoDone(String) IRemoteDispatch.RemoteDispatchAutoDone(String) 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) IRemoteDispatch.RemoteDispatchNotAutoDone(String) IRemoteDispatch.RemoteDispatchNotAutoDone(String) 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[]) IServicedComponentInfo.GetComponentInfo(Int32, String[]) IServicedComponentInfo.GetComponentInfo(Int32, String[]) IServicedComponentInfo.GetComponentInfo(Int32, String[])

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

適用於