AutoResetEvent コンストラクタとは? わかりやすく解説

Weblio 辞書 > コンピュータ > .NET Framework クラス ライブラリ リファレンス > AutoResetEvent コンストラクタの意味・解説 

AutoResetEvent コンストラクタ

初期状態シグナル状態に設定するかどうかを示す Boolean 型の値を使用して、AutoResetEvent クラス新しインスタンス初期化します。

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

Public Sub New ( _
    initialState As Boolean _
)
Dim initialState As Boolean

Dim instance As New AutoResetEvent(initialState)
public AutoResetEvent (
    bool initialState
)
public:
AutoResetEvent (
    bool initialState
)
public AutoResetEvent (
    boolean initialState
)
public function AutoResetEvent (
    initialState : boolean
)

パラメータ

initialState

初期状態シグナル状態に設定する場合true初期状態を非シグナル状態に設定する場合false

使用例使用例
Imports System
Imports System.Threading

Namespace AutoResetEvent_Examples
    Class MyMainClass
        'Initially not signaled.
        Private Const numIterations As
 Integer = 100
        Private Shared myResetEvent As
 New AutoResetEvent(False)
        Private Shared number As
 Integer

        <MTAThread> _
        Shared Sub Main()
            'Create and start the reader thread.
            Dim myReaderThread As New
 Thread(AddressOf MyReadThreadProc)
            myReaderThread.Name = "ReaderThread"
            myReaderThread.Start()

            Dim i As Integer
            For i = 1 To numIterations
                Console.WriteLine("Writer thread writing value:
 {0}", i)
                number = i

                'Signal that a value has been written.
                myResetEvent.Set()

                'Give the Reader thread an opportunity to act.
                Thread.Sleep(0)
            Next i

            'Terminate the reader thread.
            myReaderThread.Abort()
        End Sub 'Main

        Shared Sub MyReadThreadProc()
            While True
                'The value will not be read until the writer has written
                ' at least once since the last read.
                myResetEvent.WaitOne()
                Console.WriteLine("{0} reading value: {1}",
 Thread.CurrentThread.Name, number)
            End While
        End Sub 'MyReadThreadProc
    End Class 'MyMainClass
End Namespace 'AutoResetEvent_Examples
using System;
using System.Threading;

namespace AutoResetEvent_Examples
{
    class MyMainClass
    {
        //Initially not signaled.
      const int numIterations = 100;
      static AutoResetEvent myResetEvent = new
 AutoResetEvent(false);
      static int number;
      
      static void Main()
        {
         //Create and start the reader thread.
         Thread myReaderThread = new Thread(new
 ThreadStart(MyReadThreadProc));
         myReaderThread.Name = "ReaderThread";
         myReaderThread.Start();

         for(int i = 1; i <= numIterations;
 i++)
         {
            Console.WriteLine("Writer thread writing value: {0}", i);
            number = i;
            
            //Signal that a value has been written.
            myResetEvent.Set();
            
            //Give the Reader thread an opportunity to act.
            Thread.Sleep(0);
         }

         //Terminate the reader thread.
         myReaderThread.Abort();
      }

      static void MyReadThreadProc()
      {
         while(true)
         {
            //The value will not be read until the writer has written
            // at least once since the last read.
            myResetEvent.WaitOne();
            Console.WriteLine("{0} reading value: {1}", Thread.CurrentThread.Name,
 number);
         }
      }
    }
}
using namespace System;
using namespace System::Threading;
ref class MyMainClass
{
public:
   static void MyReadThreadProc()
   {
      while ( true )
      {
         
         //The value will not be read until the writer has written
         // at least once since the last read.
         myResetEvent->WaitOne();
         Console::WriteLine( " {0} reading value: {1}", Thread::CurrentThread->Name,
 number );
      }
   }


   //Initially not signaled.
   static AutoResetEvent^ myResetEvent = gcnew AutoResetEvent(
 false );
   static int number;
   literal int numIterations = 100;
};

int main()
{
   
   //Create and start the reader thread.
   Thread^ myReaderThread = gcnew Thread( gcnew ThreadStart( MyMainClass::MyReadThreadProc
 ) );
   myReaderThread->Name = "ReaderThread";
   myReaderThread->Start();
   for ( int i = 1; i <= MyMainClass::numIterations;
 i++ )
   {
      Console::WriteLine( "Writer thread writing value: {0}", i );
      MyMainClass::number = i;
      
      //Signal that a value has been written.
      MyMainClass::myResetEvent->Set();
      
      //Give the Reader thread an opportunity to act.
      Thread::Sleep( 0 );

   }
   
   //Terminate the reader thread.
   myReaderThread->Abort();
}

package AutoResetEvent_Examples;

import System.*;
import System.Threading.*;
import System.Threading.Thread;

class MyMainClass
{
    //Initially not signaled.
    private final static int
 numIterations = 100;
    private static AutoResetEvent myResetEvent
 = new AutoResetEvent(false);
    private static int number;

    public static void main(String[]
 args)
    {
        //Create and start the reader thread.
        Thread myReaderThread = new Thread(new
 ThreadStart(MyReadThreadProc));
        myReaderThread.set_Name("ReaderThread");
        myReaderThread.Start();
        for (int i = 1; i <= numIterations;
 i++) {
            Console.WriteLine("Writer thread writing value: {0}",
                String.valueOf(i));
            number = i;

            //Signal that a value has been written.
            myResetEvent.Set();

            //Give the Reader thread an opportunity to act.
            Thread.Sleep(0);
        }

        //Terminate the reader thread.
        myReaderThread.Abort();
    } //main

    static void MyReadThreadProc()
    {
        while (true) {
            //The value will not be read until the writer has written
            // at least once since the last read.
            myResetEvent.WaitOne();
            Console.WriteLine("{0} reading value: {1}", 
                Thread.get_CurrentThread().get_Name(),String.valueOf(number));
        }
    } //MyReadThreadProc
} //MyMainClass
プラットフォームプラットフォーム
バージョン情報バージョン情報
参照参照



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

辞書ショートカット

すべての辞書の索引

「AutoResetEvent コンストラクタ」の関連用語

AutoResetEvent コンストラクタのお隣キーワード
検索ランキング

   

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



AutoResetEvent コンストラクタのページの著作権
Weblio 辞書 情報提供元は 参加元一覧 にて確認できます。

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

©2025 GRAS Group, Inc.RSS