TrackingServices クラス
アセンブリ: mscorlib (mscorlib.dll 内)


追跡ハンドラは、ITrackingHandler インターフェイスを実装するオブジェクトです。リモート処理インフラストラクチャがオブジェクトまたはプロキシをマーシャリング、マーシャリング解除、または切断するときは、必ず追跡ハンドラに通知する必要があることを示しています。TrackingServices に登録されているすべてのオブジェクトは、現在の AppDomain 内のオブジェクトまたはプロキシがマーシャリング、マーシャリング解除、または切断されるときに、リモート処理によって呼び出されます。
TrackingServices クラスのすべてのメソッドは静的で、現在の AppDomain 内の追跡ハンドラで動作します。
![]() |
---|
このクラスはリンク確認要求を行います。直前の呼び出し元にインフラストラクチャ アクセス許可がない場合、SecurityException がスローされます。詳細については、「リンク確認要求」を参照してください。 |

TrackingServices クラスのメソッドを使用して追跡ハンドラの登録および登録解除を行う方法を次のコード例に示します。
using System; using System.Runtime.Remoting; using System.Runtime.Remoting.Channels; using System.Runtime.Remoting.Services; // Intercept marshal, unmarshal, and disconnect events for an object. public class TrackingHandler : ITrackingHandler { // Called when the tracked object is marshaled. [System.Security.Permissions.SecurityPermissionAttribute( System.Security.Permissions.SecurityAction.LinkDemand, Flags=System.Security.Permissions.SecurityPermissionFlag.Infrastructure)] public void MarshaledObject(Object obj, ObjRef objRef) { // Notify the user of the marshal event. Console.WriteLine("Tracking: An instance of {0} was marshaled.", obj.ToString()); // Print the channel information. if (objRef.ChannelInfo != null) { // Iterate over ChannelData. foreach(object data in objRef.ChannelInfo.ChannelData) { if (data is ChannelDataStore) { // Print the URIs from the ChannelDataStore objects. string[] uris = ((ChannelDataStore)data).ChannelUris; foreach(string uri in uris) Console.WriteLine("ChannelUri: " + uri); } } } // Print the envoy information. if (objRef.EnvoyInfo != null) Console.WriteLine("EnvoyInfo: " + objRef.EnvoyInfo.ToString()); // Print the type information. if (objRef.TypeInfo != null) { Console.WriteLine("TypeInfo: " + objRef.TypeInfo.ToString()); Console.WriteLine("TypeName: " + objRef.TypeInfo.TypeName); } // Print the URI. if (objRef.URI != null) Console.WriteLine("URI: " + objRef.URI.ToString()); } // Called when the tracked object is unmarshaled. [System.Security.Permissions.SecurityPermissionAttribute( System.Security.Permissions.SecurityAction.LinkDemand, Flags=System.Security.Permissions.SecurityPermissionFlag.Infrastructure)] public void UnmarshaledObject(Object obj, ObjRef objRef) { Console.WriteLine("Tracking: An instance of {0} was unmarshaled.", obj.ToString()); } // Called when the tracked object is disconnected. [System.Security.Permissions.SecurityPermissionAttribute( System.Security.Permissions.SecurityAction.LinkDemand, Flags=System.Security.Permissions.SecurityPermissionFlag.Infrastructure)] public void DisconnectedObject(Object obj) { Console.WriteLine("Tracking: An instance of {0} was disconnected.", obj.ToString()); } }
このクラスをサーバー上で実装する方法を次のコード例に示します。
using System; using System.Runtime.Remoting; using System.Runtime.Remoting.Channels; using System.Runtime.Remoting.Channels.Tcp; using System.Runtime.Remoting.Services; using System.Security.Permissions; public class Server { [SecurityPermission(SecurityAction.Demand)] public static void Main(string[] args) { // Register the TCP channel. TcpChannel channel = new TcpChannel(1234); ChannelServices.RegisterChannel(channel); // Register a tracking handler. ITrackingHandler handler1 = new TrackingHandler(); TrackingServices.RegisterTrackingHandler(handler1); // Register a second handler. ITrackingHandler handler2 = new TrackingHandler(); TrackingServices.RegisterTrackingHandler(handler2); // Get the number of currently registered handlers. Console.WriteLine("Registered tracking handlers: " + TrackingServices.RegisteredHandlers.Length); // Remove the tracking handler from the registered handlers. TrackingServices.UnregisterTrackingHandler(handler2); Console.WriteLine("Registered tracking handlers: " + TrackingServices.RegisteredHandlers.Length); // Create and marshal an object for remote invocation. RemoteService service = new RemoteService(); ObjRef obj = RemotingServices.Marshal(service, "TcpService"); // Wait for the user prompt. Console.WriteLine("\r\nPress ENTER to unmarshal the object."); Console.ReadLine(); // Unmarshal the object. RemotingServices.Unmarshal(obj); // Wait for the user prompt. Console.WriteLine("Press ENTER to disconnect the object."); Console.ReadLine(); // Disconnect the object. RemotingServices.Disconnect(service); } }
このクラスを前のコード例のサーバーに対するクライアントで実装する方法を次のコード例に示します。
using System; using System.Diagnostics; using System.Reflection; using System.Runtime.Remoting; using System.Runtime.Remoting.Channels; using System.Runtime.Remoting.Channels.Tcp; public class Client { public static void Main(string[] args) { // Register the TCP channel. ChannelServices.RegisterChannel(new TcpChannel()); // Register the client for the remote object. WellKnownClientTypeEntry remoteType = new WellKnownClientTypeEntry( typeof(RemoteService),"tcp://localhost:1234/TcpService"); RemotingConfiguration.RegisterWellKnownClientType(remoteType); // Create an instance of the remote object. RemoteService service = new RemoteService(); // Invoke a method on the remote object. service.Hello("world"); Console.WriteLine("Hello invoked on server."); } }
サーバーとクライアントによって使用されるリモート オブジェクトを次のコード例に示します。
using System; using System.Diagnostics; using System.Runtime.Remoting; using System.Runtime.Remoting.Channels; // Remote object. public class RemoteService : MarshalByRefObject { private DateTime startTime; public RemoteService() { // Notify the user that the constructor was invoked. Console.WriteLine("Constructor invoked."); startTime = DateTime.Now; } ~RemoteService() { // Notify the user that the destructor was invoked. TimeSpan elapsedTime = new TimeSpan(DateTime.Now.Ticks - startTime.Ticks); Console.WriteLine("Destructor invoked after " + elapsedTime.ToString() + " seconds."); } public void Hello(string name) { // Print a simple message. Console.WriteLine("Hello, " + name); } }


System.Runtime.Remoting.Services.TrackingServices


Windows 98, Windows 2000 SP4, Windows Millennium Edition, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition
開発プラットフォームの中には、.NET Framework によってサポートされていないバージョンがあります。サポートされているバージョンについては、「システム要件」を参照してください。


TrackingServices コンストラクタ
アセンブリ: mscorlib (mscorlib.dll 内)


Windows 98, Windows 2000 SP4, Windows Millennium Edition, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition
開発プラットフォームの中には、.NET Framework によってサポートされていないバージョンがあります。サポートされているバージョンについては、「システム要件」を参照してください。


TrackingServices プロパティ
TrackingServices メソッド

名前 | 説明 | |
---|---|---|
![]() | Equals | オーバーロードされます。 2 つの Object インスタンスが等しいかどうかを判断します。 ( Object から継承されます。) |
![]() | GetHashCode | 特定の型のハッシュ関数として機能します。GetHashCode は、ハッシュ アルゴリズムや、ハッシュ テーブルのようなデータ構造での使用に適しています。 ( Object から継承されます。) |
![]() | GetType | 現在のインスタンスの Type を取得します。 ( Object から継承されます。) |
![]() | ReferenceEquals | 指定した複数の Object インスタンスが同一かどうかを判断します。 ( Object から継承されます。) |
![]() | RegisterTrackingHandler | TrackingServices に新しい追跡ハンドラを登録します。 |
![]() | ToString | 現在の Object を表す String を返します。 ( Object から継承されます。) |
![]() | UnregisterTrackingHandler | TrackingServices から、指定した追跡ハンドラの登録を解除します。 |

名前 | 説明 | |
---|---|---|
![]() | Finalize | Object がガベージ コレクションにより収集される前に、その Object がリソースを解放し、その他のクリーンアップ操作を実行できるようにします。 ( Object から継承されます。) |
![]() | MemberwiseClone | 現在の Object の簡易コピーを作成します。 ( Object から継承されます。) |

TrackingServices メンバ
追跡ハンドラのリストに登録および登録解除したり、追跡ハンドラのリストを取得したりする方法を提供します。
TrackingServices データ型で公開されるメンバを以下の表に示します。

名前 | 説明 | |
---|---|---|
![]() | TrackingServices |


名前 | 説明 | |
---|---|---|
![]() | Equals | オーバーロードされます。 2 つの Object インスタンスが等しいかどうかを判断します。 (Object から継承されます。) |
![]() | GetHashCode | 特定の型のハッシュ関数として機能します。GetHashCode は、ハッシュ アルゴリズムや、ハッシュ テーブルのようなデータ構造での使用に適しています。 (Object から継承されます。) |
![]() | GetType | 現在のインスタンスの Type を取得します。 (Object から継承されます。) |
![]() | ReferenceEquals | 指定した複数の Object インスタンスが同一かどうかを判断します。 (Object から継承されます。) |
![]() | RegisterTrackingHandler | TrackingServices に新しい追跡ハンドラを登録します。 |
![]() | ToString | 現在の Object を表す String を返します。 (Object から継承されます。) |
![]() | UnregisterTrackingHandler | TrackingServices から、指定した追跡ハンドラの登録を解除します。 |

名前 | 説明 | |
---|---|---|
![]() | Finalize | Object がガベージ コレクションにより収集される前に、その Object がリソースを解放し、その他のクリーンアップ操作を実行できるようにします。 (Object から継承されます。) |
![]() | MemberwiseClone | 現在の Object の簡易コピーを作成します。 (Object から継承されます。) |

- TrackingServicesのページへのリンク