SynchronizationAttribute クラス
アセンブリ: System.EnterpriseServices (system.enterpriseservices.dll 内)

<ComVisibleAttribute(False)> _ <AttributeUsageAttribute(AttributeTargets.Class, Inherited:=True)> _ Public NotInheritable Class SynchronizationAttribute Inherits Attribute
[ComVisibleAttribute(false)] [AttributeUsageAttribute(AttributeTargets.Class, Inherited=true)] public sealed class SynchronizationAttribute : Attribute
[ComVisibleAttribute(false)] [AttributeUsageAttribute(AttributeTargets::Class, Inherited=true)] public ref class SynchronizationAttribute sealed : public Attribute

同期はトランザクションとジャスト イン タイム (JIT: Just-In-Time) の両方のアクティベーションによって自動的に有効になります。
属性の使用方法については、「属性を使用したメタデータの拡張」を参照してください。
SynchronizationAttribute をコンテキスト バインド オブジェクトに適用すると、待機ハンドルと自動リセット イベントが作成されます。この待機ハンドルと自動リセット イベントは、ガベージ コレクションで収集されないことがあります。したがって、短期間に SynchronizationAttribute でマークされたコンテキスト バインド オブジェクトを大量に作成しないでください。

SynchronizationAttribute 型の使用方法のコード例を次に示します。
Imports System Imports System.EnterpriseServices Imports System.Reflection ' References: ' System.EnterpriseServices ' This is equivalent to [Synchronization(SynchronizationOption.Required)]. <Synchronization()> _ Public Class SynchronizationAttribute_Ctor Inherits ServicedComponent End Class 'SynchronizationAttribute_Ctor <Synchronization(SynchronizationOption.Disabled)> _ Public Class SynchronizationAttribute_Ctor_SynchronizationOption Inherits ServicedComponent End Class 'SynchronizationAttribute_Ctor_SynchronizationOption <Synchronization(SynchronizationOption.RequiresNew)> _ Public Class SynchronizationAttribute_Value Inherits ServicedComponent Public Sub ValueExample() ' Get the SynchronizationAttribute applied to the class. Dim attribute As SynchronizationAttribute = CType(Attribute.GetCustomAttribute(Me.GetType(), GetType(SynchronizationAttribute), False), SynchronizationAttribute) ' Display the value of the attribute's Value property. MsgBox("SynchronizationAttribute.Value: " & attribute.Value) End Sub 'ValueExample End Class 'SynchronizationAttribute_Value
using System; using System.EnterpriseServices; using System.Reflection; // References: // System.EnterpriseServices // This is equivalent to [Synchronization(SynchronizationOption.Required)]. [Synchronization] public class SynchronizationAttribute_Ctor : ServicedComponent { } [Synchronization(SynchronizationOption.Disabled)] public class SynchronizationAttribute_Ctor_SynchronizationOption : ServicedComponent { } [Synchronization(SynchronizationOption.RequiresNew)] public class SynchronizationAttribute_Value : ServicedComponent { public void ValueExample() { // Get the SynchronizationAttribute applied to the class. SynchronizationAttribute attribute = (SynchronizationAttribute)Attribute.GetCustomAttribute( this.GetType(), typeof(SynchronizationAttribute), false); // Display the value of the attribute's Value property. Console.WriteLine("SynchronizationAttribute.Value: {0}", attribute.Value); } }
import System.*; import System.EnterpriseServices.*; import System.Reflection.*; // References: // System.EnterpriseServices // This is equivalent to [Synchronization(SynchronizationOption.Required)]. /** @attribute Synchronization() */ public class SynchronizationAttribute_Ctor extends ServicedComponent { } //SynchronizationAttribute_Ctor /** @attribute Synchronization(SynchronizationOption.Disabled) */ public class SynchronizationAttribute_Ctor_SynchronizationOption extends ServicedComponent { } //SynchronizationAttribute_Ctor_SynchronizationOption /** @attribute Synchronization(SynchronizationOption.RequiresNew) */ public class SynchronizationAttribute_Value extends ServicedComponent { public void ValueExample() { // Get the SynchronizationAttribute applied to the class. SynchronizationAttribute attribute = (SynchronizationAttribute)( Attribute.GetCustomAttribute(this.GetType(), SynchronizationAttribute.class.ToType(), false)); // Display the value of the attribute's Value property. Console.WriteLine("SynchronizationAttribute.Value: {0}", attribute.get_Value()); } //ValueExample } //SynchronizationAttribute_Value

System.Attribute
System.EnterpriseServices.SynchronizationAttribute


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


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

<SerializableAttribute> _ <AttributeUsageAttribute(AttributeTargets.Class)> _ <ComVisibleAttribute(True)> _ Public Class SynchronizationAttribute Inherits ContextAttribute Implements IContributeServerContextSink, IContributeClientContextSink
[SerializableAttribute] [AttributeUsageAttribute(AttributeTargets.Class)] [ComVisibleAttribute(true)] public class SynchronizationAttribute : ContextAttribute, IContributeServerContextSink, IContributeClientContextSink
[SerializableAttribute] [AttributeUsageAttribute(AttributeTargets::Class)] [ComVisibleAttribute(true)] public ref class SynchronizationAttribute : public ContextAttribute, IContributeServerContextSink, IContributeClientContextSink

この属性をオブジェクトに適用する場合、このプロパティのインスタンスを共有するすべてのコンテキスト内で実行できるスレッドは 1 つだけです。それぞれのコンテキストの着信呼び出しを受け取り、シリアル化するシンクを提供することによって実行されます。プロパティが再エントリとしてマークされている場合は、コールアウトも受け取られます。コールアウトを受け取ることにより、待機している他のスレッドが同期ドメインに参加できるようになり、最大限のスループットを実現できます。
![]() |
---|
SynchronizationAttribute という名前のクラスが 2 つあります。1 つは System.Runtime.Remoting.Contexts 名前空間に格納され、もう 1 つは System.EnterpriseServices 名前空間に格納されています。System.EnterpriseServices.SynchronizationAttribute クラスは、同期呼び出しだけをサポートし、サービス コンポーネントだけで使用できます。サービス コンポーネントの詳細については、「サービス コンポーネントの概要」を参照してください。System.Runtime.Remoting.Contexts.SynchronizationAttribute は、同期呼び出しおよび非同期呼び出しをサポートし、コンテキスト バインド オブジェクトだけで使用できます。コンテキスト バインド オブジェクトの詳細については ContextBoundObject クラスのトピックを参照してください。 |

SynchronizationAttribute の使用方法については、次のコード例を参照してください。プログラム例の全体については、AsyncResult クラスのトピックの例を参照してください。
' Context-bound type with the Synchronization context attribute. <Synchronization()> Public Class SampleSyncronized Inherits ContextBoundObject ' A method that does some work, and returns the square of the given number. Public Function Square(i As Integer) As Integer Console.Write("The hash of the thread executing ") Console.WriteLine("SampleSyncronized.Square is: {0}", Thread.CurrentThread.GetHashCode()) Return i * i End Function 'Square End Class 'SampleSyncronized
// Context-bound type with the Synchronization context attribute. [Synchronization()] public class SampleSyncronized : ContextBoundObject { // A method that does some work, and returns the square of the given number. public int Square(int i) { Console.Write("The hash of the thread executing "); Console.WriteLine("SampleSyncronized.Square is: {0}", Thread.CurrentThread.GetHashCode()); return i*i; } }
// Context-bound type with the Synchronization context attribute. [Synchronization] public ref class SampleSyncronized: public ContextBoundObject { public: // A method that does some work, and returns the square of the given number. int Square( int i ) { Console::Write( "The hash of the thread executing " ); Console::WriteLine( "SampleSyncronized::Square is: {0}", Thread::CurrentThread->GetHashCode() ); return i * i; } };
// Context-bound type with the Synchronization context attribute. /** @attribute Synchronization() */ public class SampleSyncronized extends ContextBoundObject { // A method that does some work, and returns the square of the given number. public int Square(int i) { Console.Write("The hash of the thread executing "); Console.WriteLine("SampleSyncronized.Square is: {0}", (Int32)System.Threading.Thread.get_CurrentThread().GetHashCode()); return i * i; } //Square } //SampleSyncronized


System.Attribute
System.Runtime.Remoting.Contexts.ContextAttribute
System.Runtime.Remoting.Contexts.SynchronizationAttribute


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 によってサポートされていないバージョンがあります。サポートされているバージョンについては、「システム要件」を参照してください。


- SynchronizationAttribute クラスのページへのリンク