SemaphoreFullExceptionとは? わかりやすく解説

SemaphoreFullException クラス

メモ : このクラスは、.NET Framework version 2.0 で新しく追加されたものです。

カウントが既に最大値であるセマフォに対して System.Threading.Semaphore.Release メソッドが呼び出された場合にスローされる例外。

名前空間: System.Threading
アセンブリ: System (system.dll 内)
構文構文

<SerializableAttribute> _
<ComVisibleAttribute(False)> _
Public Class SemaphoreFullException
    Inherits SystemException
Dim instance As SemaphoreFullException
[SerializableAttribute] 
[ComVisibleAttribute(false)] 
public class SemaphoreFullException : SystemException
[SerializableAttribute] 
[ComVisibleAttribute(false)] 
public ref class SemaphoreFullException : public
 SystemException
/** @attribute SerializableAttribute() */ 
/** @attribute ComVisibleAttribute(false) */ 
public class SemaphoreFullException extends
 SystemException
SerializableAttribute 
ComVisibleAttribute(false) 
public class SemaphoreFullException extends
 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.Object
   System.Exception
     System.SystemException
      System.Threading.SemaphoreFullException
スレッド セーフスレッド セーフ
この型の public static (Visual Basic では Shared) メンバはすべて、スレッド セーフです。インスタンス メンバの場合は、スレッド セーフであるとは限りません。
プラットフォームプラットフォーム
バージョン情報バージョン情報
参照参照

SemaphoreFullException コンストラクタ ()

メモ : このコンストラクタは、.NET Framework version 2.0 で新しく追加されたものです。

SemaphoreFullException クラスの新しいインスタンスを既定値で初期化します。

名前空間: System.Threading
アセンブリ: System (system.dll 内)
構文構文

Dim instance As New SemaphoreFullException
public SemaphoreFullException ()
public:
SemaphoreFullException ()
public SemaphoreFullException ()
public function SemaphoreFullException ()
解説解説
プラットフォームプラットフォーム
バージョン情報バージョン情報
参照参照

SemaphoreFullException コンストラクタ (String, Exception)

メモ : このコンストラクタは、.NET Framework version 2.0 で新しく追加されたものです。

指定したエラー メッセージと、この例外の原因である内部例外への参照を使用して、SemaphoreFullException クラスの新しいインスタンスを初期化します。

名前空間: System.Threading
アセンブリ: System (system.dll 内)
構文構文

Public Sub New ( _
    message As String, _
    innerException As Exception _
)
Dim message As String
Dim innerException As Exception

Dim instance As New SemaphoreFullException(message,
 innerException)
public SemaphoreFullException (
    string message,
    Exception innerException
)
public:
SemaphoreFullException (
    String^ message, 
    Exception^ innerException
)
public SemaphoreFullException (
    String message, 
    Exception innerException
)
public function SemaphoreFullException (
    message : String, 
    innerException : Exception
)

パラメータ

message

例外の原因を説明するエラー メッセージ。

innerException

現在の例外の原因である例外。innerException パラメータが null 参照 (Visual Basic では Nothing) でない場合は、内部例外を処理する catch ブロックで現在の例外が発生します。

解説解説

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

プラットフォームプラットフォーム
バージョン情報バージョン情報
参照参照

SemaphoreFullException コンストラクタ (String)

メモ : このコンストラクタは、.NET Framework version 2.0 で新しく追加されたものです。

指定したエラー メッセージを使用して、SemaphoreFullException クラスの新しいインスタンスを初期化します。

名前空間: System.Threading
アセンブリ: System (system.dll 内)
構文構文

Dim message As String

Dim instance As New SemaphoreFullException(message)
public SemaphoreFullException (
    string message
)
public:
SemaphoreFullException (
    String^ message
)
public SemaphoreFullException (
    String message
)
public function SemaphoreFullException (
    message : String
)

パラメータ

message

例外の原因を説明するエラー メッセージ。

解説解説
プラットフォームプラットフォーム
バージョン情報バージョン情報
参照参照

SemaphoreFullException コンストラクタ

SemaphoreFullException クラスの新しいインスタンスを初期化します。
オーバーロードの一覧オーバーロードの一覧

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

関連項目

SemaphoreFullException クラス
SemaphoreFullException メンバ
System.Threading 名前空間
Semaphore クラス

その他の技術情報

セマフォ

SemaphoreFullException コンストラクタ (SerializationInfo, StreamingContext)

メモ : このコンストラクタは、.NET Framework version 2.0 で新しく追加されたものです。

シリアル化したデータを使用して、SemaphoreFullException クラスの新しいインスタンスを初期化します。

名前空間: System.Threading
アセンブリ: System (system.dll 内)
構文構文

Protected Sub New ( _
    info As SerializationInfo, _
    context As StreamingContext _
)
Dim info As SerializationInfo
Dim context As StreamingContext

Dim instance As New SemaphoreFullException(info,
 context)
protected SemaphoreFullException (
    SerializationInfo info,
    StreamingContext context
)
protected:
SemaphoreFullException (
    SerializationInfo^ info, 
    StreamingContext context
)
protected SemaphoreFullException (
    SerializationInfo info, 
    StreamingContext context
)
protected function SemaphoreFullException (
    info : SerializationInfo, 
    context : StreamingContext
)

パラメータ

info

スローされている例外に関するシリアル化済みオブジェクト データを保持している SerializationInfo オブジェクト。

context

転送元または転送先に関するコンテキスト情報を含んでいる StreamingContext オブジェクト。

解説解説
プラットフォームプラットフォーム
バージョン情報バージョン情報
参照参照

SemaphoreFullException プロパティ


パブリック プロパティパブリック プロパティ

プロテクト プロパティプロテクト プロパティ
  名前 説明
プロテクト プロパティ HResult  特定の例外に割り当てられているコード化数値である HRESULT を取得または設定します。 ( Exception から継承されます。)
参照参照

関連項目

SemaphoreFullException クラス
System.Threading 名前空間
Semaphore クラス

その他の技術情報

セマフォ

SemaphoreFullException メソッド


パブリック メソッドパブリック メソッド

プロテクト メソッドプロテクト メソッド
参照参照

関連項目

SemaphoreFullException クラス
System.Threading 名前空間
Semaphore クラス

その他の技術情報

セマフォ

SemaphoreFullException メンバ

カウントが既に最大値であるセマフォに対して System.Threading.Semaphore.Release メソッドが呼び出された場合にスローされる例外。

SemaphoreFullException データ型で公開されるメンバを以下の表に示します。


パブリック コンストラクタパブリック コンストラクタ
プロテクト コンストラクタプロテクト コンストラクタ
  名前 説明
プロテクト メソッド SemaphoreFullException オーバーロードされます。 SemaphoreFullException クラスの新しいインスタンスを初期化します。
パブリック プロパティパブリック プロパティ
プロテクト プロパティプロテクト プロパティ
  名前 説明
プロテクト プロパティ HResult  特定の例外に割り当てられているコード化数値である HRESULT を取得または設定します。(Exception から継承されます。)
パブリック メソッドパブリック メソッド
プロテクト メソッドプロテクト メソッド
参照参照

関連項目

SemaphoreFullException クラス
System.Threading 名前空間
Semaphore クラス

その他の技術情報

セマフォ



英和和英テキスト翻訳

英語⇒日本語日本語⇒英語

辞書ショートカット

すべての辞書の索引

「SemaphoreFullException」の関連用語

SemaphoreFullExceptionのお隣キーワード
検索ランキング

   

英語⇒日本語
日本語⇒英語
   



SemaphoreFullExceptionのページの著作権

   
日本マイクロソフト株式会社日本マイクロソフト株式会社
© 2026 Microsoft.All rights reserved.

©2026 GRAS Group, Inc.RSS