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 クラス

その他の技術情報

セマフォ



英和和英テキスト翻訳>> Weblio翻訳
英語⇒日本語日本語⇒英語
  

辞書ショートカット

すべての辞書の索引

「SemaphoreFullException」の関連用語

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

   

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



SemaphoreFullExceptionのページの著作権
Weblio 辞書 情報提供元は 参加元一覧 にて確認できます。

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

©2025 GRAS Group, Inc.RSS