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

<SerializableAttribute> _ <ComVisibleAttribute(False)> _ Public Class SemaphoreFullException Inherits SystemException
[SerializableAttribute] [ComVisibleAttribute(false)] public class SemaphoreFullException : SystemException
[SerializableAttribute] [ComVisibleAttribute(false)] public ref class SemaphoreFullException : public SystemException

セマフォのカウントは、1 つのスレッドがセマフォに入るたびにデクリメントされ、1 つのスレッドがセマフォを解放するたびにインクリメントされます。カウントが 0 になると、それ以降の要求は他のスレッドがセマフォを解放するまでブロックされます。すべてのスレッドがセマフォを解放すると、カウントはセマフォの作成時に設定された最大値になります。プログラミング エラーによってこの時点でスレッドが System.Threading.Semaphore.Release メソッドを呼び出した場合、SemaphoreFullException がスローされます。
![]() |
---|
Semaphore クラスは、System.Threading.WaitHandle.WaitOne および System.Threading.Semaphore.Release メソッドの呼び出しにスレッドの ID を適用しません。WaitOne を呼び出したスレッドと Release を呼び出すメソッドが同じである必要はありません。 |
SemaphoreFullException は、この例外が発生したコードに問題があることを示すとは限りません。たとえば、スレッド A とスレッド B が、カウントの最大値が 2 のセマフォに入ったとします。スレッド B がプログラミング エラーによって Release を 2 回呼び出した場合、セマフォのカウントは最大値になります。その結果、スレッド A が最終的に Release を呼び出すと、SemaphoreFullException がスローされます。
SemaphoreFullException クラスのインスタンスの初期プロパティ値の一覧については、SemaphoreFullException コンストラクタのトピックを参照してください。

1 つのスレッドにプログラミング エラーがあるために、別のスレッドに対して SemaphoreFullException がスローされるコード例を次に示します。この例では、2 つのスレッドがセマフォに入ります。1 番目のスレッドがタスクを実行している間に、2 番目のスレッドがセマフォを 2 回解放します。1 番目のスレッドがタスクを完了してセマフォを解放しようとすると、セマフォのカウントが既に最大値になっているために、例外がスローされます。
Imports System Imports System.Threading Public Class Example ' A semaphore that can satisfy at most two concurrent ' requests. ' Private Shared _pool As New Semaphore(2, 2) <MTAThread> _ Public Shared Sub Main() ' Create and start two threads, A and B. ' Dim tA As New Thread(AddressOf ThreadA) tA.Start() Dim tB As New Thread(AddressOf ThreadB) tB.Start() End Sub Private Shared Sub ThreadA() ' Thread A enters the semaphore and simulates a task ' that lasts a second. ' _pool.WaitOne() Console.WriteLine("Thread A entered the semaphore.") Thread.Sleep(1000) Try _pool.Release() Console.WriteLine("Thread A released the semaphore.") Catch ex As Exception Console.WriteLine("Thread A: {0}", ex.Message) End Try End Sub Private Shared Sub ThreadB() ' Thread B simulates a task that lasts half a second, ' then enters the semaphore. ' Thread.Sleep(500) _pool.WaitOne() Console.WriteLine("Thread B entered the semaphore.") ' Due to a programming error, Thread B releases the ' semaphore twice. To fix the program, delete one line. _pool.Release() _pool.Release() Console.WriteLine("Thread B exits successfully.") End Sub End Class ' This code example produces the following output: ' ' Thread A entered the semaphore. ' Thread B entered the semaphore. ' Thread B exits successfully. ' Thread A: Adding the given count to the semaphore would cause it to exceed its maximum count. '
using System; using System.Threading; public class Example { // A semaphore that can satisfy at most two concurrent // requests. // private static Semaphore _pool = new Semaphore(2, 2); public static void Main() { // Create and start two threads, A and B. // Thread tA = new Thread(new ThreadStart(ThreadA)); tA.Start(); Thread tB = new Thread(new ThreadStart(ThreadB)); tB.Start(); } private static void ThreadA() { // Thread A enters the semaphore and simulates a task // that lasts a second. // _pool.WaitOne(); Console.WriteLine("Thread A entered the semaphore."); Thread.Sleep(1000); try { _pool.Release(); Console.WriteLine("Thread A released the semaphore."); } catch(Exception ex) { Console.WriteLine("Thread A: {0}", ex.Message); } } private static void ThreadB() { // Thread B simulates a task that lasts half a second, // then enters the semaphore. // Thread.Sleep(500); _pool.WaitOne(); Console.WriteLine("Thread B entered the semaphore."); // Due to a programming error, Thread B releases the // semaphore twice. To fix the program, delete one line. _pool.Release(); _pool.Release(); Console.WriteLine("Thread B exits successfully."); } } /* This code example produces the following output: Thread A entered the semaphore. Thread B entered the semaphore. Thread B exits successfully. Thread A: Adding the given count to the semaphore would cause it to exceed its maximum count. */
#using <System.dll> using namespace System; using namespace System::Threading; public ref class Example { private: // A semaphore that can satisfy at most two concurrent // requests. // static Semaphore^ _pool = gcnew Semaphore( 2,2 ); public: static void main() { // Create and start two threads, A and B. // Thread^ tA = gcnew Thread( gcnew ThreadStart( ThreadA ) ); tA->Start(); Thread^ tB = gcnew Thread( gcnew ThreadStart( ThreadB ) ); tB->Start(); } private: static void ThreadA() { // Thread A enters the semaphore and simulates a task // that lasts a second. // _pool->WaitOne(); Console::WriteLine( L"Thread A entered the semaphore." ); Thread::Sleep( 1000 ); try { _pool->Release(); Console::WriteLine( L"Thread A released the semaphore." ); } catch ( Exception^ ex ) { Console::WriteLine( L"Thread A: {0}", ex->Message ); } } static void ThreadB() { // Thread B simulates a task that lasts half a second, // then enters the semaphore. // Thread::Sleep( 500 ); _pool->WaitOne(); Console::WriteLine( L"Thread B entered the semaphore." ); // Due to a programming error, Thread B releases the // semaphore twice. To fix the program, delete one line. _pool->Release(); _pool->Release(); Console::WriteLine( L"Thread B exits successfully." ); } }; /* This code example produces the following output: Thread A entered the semaphore. Thread B entered the semaphore. Thread B exits successfully. Thread A: Adding the given count to the semaphore would cause it to exceed its maximum count. */
import System.*; import System.Threading.*; public class Example { // A semaphore that can satisfy at most two concurrent // requests. // private static Semaphore pool = new Semaphore(2, 2); public static void main(String[] args) { // Create and start two threads, A and B. // System.Threading.Thread tA = new System.Threading.Thread(new ThreadStart(ThreadA)); tA.Start(); System.Threading.Thread tB = new System.Threading.Thread(new ThreadStart(ThreadB)); tB.Start(); } //main private static void ThreadA() { // Thread A enters the semaphore and simulates a task // that lasts a second. // pool.WaitOne(); Console.WriteLine("Thread A entered the semaphore."); System.Threading.Thread.Sleep(1000); try { pool.Release(); Console.WriteLine("Thread A released the semaphore."); } catch (System.Exception ex) { Console.WriteLine("Thread A: {0}", ex.get_Message()); } } //ThreadA private static void ThreadB() { // Thread B simulates a task that lasts half a second, // then enters the semaphore. // System.Threading.Thread.Sleep(500); pool.WaitOne(); Console.WriteLine("Thread B entered the semaphore."); // Due to a programming error, Thread B releases the // semaphore twice. To fix the program, delete one line. pool.Release(); pool.Release(); Console.WriteLine("Thread B exits successfully."); } //ThreadB } //Example /* This code example produces the following output: Thread A entered the semaphore. Thread B entered the semaphore. Thread B exits successfully. Thread A: Adding the given count to the semaphore would cause it to exceed its maximum count. */

System.Exception
System.SystemException
System.Threading.SemaphoreFullException


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


SemaphoreFullException コンストラクタ ()
アセンブリ: System (system.dll 内)


このコンストラクタは、新しいインスタンスの Message プロパティを初期化して、その値に "セマフォに指定されたカウントを追加すると、カウントの最大値を超える可能性があります。" などのエラーを説明するシステム提供のメッセージを設定します。このメッセージは、システムの現在のカルチャを考慮して指定します。
SemaphoreFullException クラスのインスタンスの初期プロパティ値を次の表に示します。

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


SemaphoreFullException コンストラクタ (String, Exception)
アセンブリ: System (system.dll 内)

Dim message As String Dim innerException As Exception Dim instance As New SemaphoreFullException(message, innerException)

前の例外の直接の結果としてスローされる例外については、InnerException プロパティに、前の例外への参照が格納されます。InnerException プロパティは、コンストラクタに渡されたものと同じ値を返します。InnerException プロパティによって内部例外値がコンストラクタに渡されなかった場合は、null 参照 (Visual Basic では Nothing) を返します。

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


SemaphoreFullException コンストラクタ (String)
アセンブリ: System (system.dll 内)


message の内容は、例外に関する情報をユーザーに伝えるためのテキスト文字列です。このコンストラクタの呼び出し元は、この文字列が現在のシステムのカルチャに合わせてローカライズ済みであることを確認しておく必要があります。
このコンストラクタを使用して初期化する SemaphoreFullException クラスのインスタンスの初期プロパティ値を次の表に示します。

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


SemaphoreFullException コンストラクタ

名前 | 説明 |
---|---|
SemaphoreFullException () | SemaphoreFullException クラスの新しいインスタンスを既定値で初期化します。 |
SemaphoreFullException (String) | 指定したエラー メッセージを使用して、SemaphoreFullException クラスの新しいインスタンスを初期化します。 |
SemaphoreFullException (SerializationInfo, StreamingContext) | シリアル化したデータを使用して、SemaphoreFullException クラスの新しいインスタンスを初期化します。 |
SemaphoreFullException (String, Exception) | 指定したエラー メッセージと、この例外の原因である内部例外への参照を使用して、SemaphoreFullException クラスの新しいインスタンスを初期化します。 |

SemaphoreFullException コンストラクタ (SerializationInfo, StreamingContext)
アセンブリ: System (system.dll 内)

Dim info As SerializationInfo Dim context As StreamingContext Dim instance As New SemaphoreFullException(info, context)


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


SemaphoreFullException プロパティ

名前 | 説明 | |
---|---|---|
![]() | Data | 例外に関する追加のユーザー定義情報を提供するキー/値ペアのコレクションを取得します。 ( Exception から継承されます。) |
![]() | HelpLink | 例外に関連付けられているヘルプ ファイルへのリンクを取得または設定します。 ( Exception から継承されます。) |
![]() | InnerException | 現在の例外を発生させた Exception インスタンスを取得します。 ( Exception から継承されます。) |
![]() | Message | 現在の例外を説明するメッセージを取得します。 ( Exception から継承されます。) |
![]() | Source | エラーの原因となったアプリケーションまたはオブジェクトの名前を取得または設定します。 ( Exception から継承されます。) |
![]() | StackTrace | 現在の例外がスローされたときにコール スタックにあったフレームの文字列形式を取得します。 ( Exception から継承されます。) |
![]() | TargetSite | 現在の例外をスローするメソッドを取得します。 ( Exception から継承されます。) |


SemaphoreFullException メソッド

名前 | 説明 | |
---|---|---|
![]() | Equals | オーバーロードされます。 2 つの Object インスタンスが等しいかどうかを判断します。 ( Object から継承されます。) |
![]() | GetBaseException | 派生クラスでオーバーライドされた場合、それ以後に発生する 1 つ以上の例外の主要な原因である Exception を返します。 ( Exception から継承されます。) |
![]() | GetHashCode | 特定の型のハッシュ関数として機能します。GetHashCode は、ハッシュ アルゴリズムや、ハッシュ テーブルのようなデータ構造での使用に適しています。 ( Object から継承されます。) |
![]() | GetObjectData | 派生クラスでオーバーライドされた場合は、その例外に関する情報を使用して SerializationInfo を設定します。 ( Exception から継承されます。) |
![]() | GetType | 現在のインスタンスのランタイム型を取得します。 ( Exception から継承されます。) |
![]() | ReferenceEquals | 指定した複数の Object インスタンスが同一かどうかを判断します。 ( Object から継承されます。) |
![]() | ToString | 現在の例外の文字列形式を作成して返します。 ( Exception から継承されます。) |

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

SemaphoreFullException メンバ
カウントが既に最大値であるセマフォに対して System.Threading.Semaphore.Release メソッドが呼び出された場合にスローされる例外。
SemaphoreFullException データ型で公開されるメンバを以下の表に示します。

名前 | 説明 | |
---|---|---|
![]() | SemaphoreFullException | オーバーロードされます。 SemaphoreFullException クラスの新しいインスタンスを初期化します。 |


名前 | 説明 | |
---|---|---|
![]() | Data | 例外に関する追加のユーザー定義情報を提供するキー/値ペアのコレクションを取得します。(Exception から継承されます。) |
![]() | HelpLink | 例外に関連付けられているヘルプ ファイルへのリンクを取得または設定します。(Exception から継承されます。) |
![]() | InnerException | 現在の例外を発生させた Exception インスタンスを取得します。(Exception から継承されます。) |
![]() | Message | 現在の例外を説明するメッセージを取得します。(Exception から継承されます。) |
![]() | Source | エラーの原因となったアプリケーションまたはオブジェクトの名前を取得または設定します。(Exception から継承されます。) |
![]() | StackTrace | 現在の例外がスローされたときにコール スタックにあったフレームの文字列形式を取得します。(Exception から継承されます。) |
![]() | TargetSite | 現在の例外をスローするメソッドを取得します。(Exception から継承されます。) |


名前 | 説明 | |
---|---|---|
![]() | Equals | オーバーロードされます。 2 つの Object インスタンスが等しいかどうかを判断します。 (Object から継承されます。) |
![]() | GetBaseException | 派生クラスでオーバーライドされた場合、それ以後に発生する 1 つ以上の例外の主要な原因である Exception を返します。 (Exception から継承されます。) |
![]() | GetHashCode | 特定の型のハッシュ関数として機能します。GetHashCode は、ハッシュ アルゴリズムや、ハッシュ テーブルのようなデータ構造での使用に適しています。 (Object から継承されます。) |
![]() | GetObjectData | 派生クラスでオーバーライドされた場合は、その例外に関する情報を使用して SerializationInfo を設定します。 (Exception から継承されます。) |
![]() | GetType | 現在のインスタンスのランタイム型を取得します。 (Exception から継承されます。) |
![]() | ReferenceEquals | 指定した複数の Object インスタンスが同一かどうかを判断します。 (Object から継承されます。) |
![]() | ToString | 現在の例外の文字列形式を作成して返します。 (Exception から継承されます。) |

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

- SemaphoreFullExceptionのページへのリンク