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

Thread クラス

スレッドを作成および制御し、そのスレッドの優先順位の設定およびステータスの取得を行います。

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

<ComVisibleAttribute(True)> _
<ClassInterfaceAttribute(ClassInterfaceType.None)> _
Public NotInheritable Class
 Thread
    Inherits CriticalFinalizerObject
    Implements _Thread
[ComVisibleAttribute(true)] 
[ClassInterfaceAttribute(ClassInterfaceType.None)] 
public sealed class Thread : CriticalFinalizerObject,
 _Thread
[ComVisibleAttribute(true)] 
[ClassInterfaceAttribute(ClassInterfaceType::None)] 
public ref class Thread sealed : public
 CriticalFinalizerObject, _Thread
/** @attribute ComVisibleAttribute(true) */ 
/** @attribute ClassInterfaceAttribute(ClassInterfaceType.None) */ 
public final class Thread extends CriticalFinalizerObject
 implements _Thread
ComVisibleAttribute(true) 
ClassInterfaceAttribute(ClassInterfaceType.None) 
public final class Thread extends
 CriticalFinalizerObject implements _Thread
解説解説

プロセスは、そのプロセスに関連付けられたプログラム コードの一部を実行する 1 つ以上のスレッドを作成できます。スレッドで実行するプログラム コードを指定するには、ThreadStart デリゲートまたは ParameterizedThreadStart デリゲートを使用します。ParameterizedThreadStart デリゲートを使用すると、スレッド プロシージャにデータを渡すことができます。

スレッドは、存在している間は常に、ThreadState で 1 つ以上定義した状態を保ちます。スレッドに対しては、ThreadPriority で定義したスケジューリング優先順位を要求できますが、その優先順位がオペレーティング システムで有効であるかどうかは保証されません。

GetHashCode を使用すると、マネージ スレッドの識別子の値を取得できます。スレッドの有効期間の間は、この値の取得元のアプリケーション ドメインに関係なく、他のスレッドの値と衝突することはありません。

メモメモ

オペレーティング システムの ThreadId は、マネージ スレッドとの固定的な関係を一切持ちません。アンマネージ ホストは、マネージ スレッドとアンマネージ スレッドの関係を制御できるためです。たとえば、高度なホストでは、CLR Hosting API を使用して、同一のオペレーティング システム スレッドに対して複数のマネージ スレッドをスケジュールしたり、1 つのマネージ スレッドを複数のオペレーティング システム スレッド間で移動させたりすることができます。

使用例使用例

単純なスレッド機能を示すコード例を次に示します。

Imports System
Imports System.Threading

' Simple threading scenario:  Start a Shared method running
' on a second thread.
Public Class ThreadExample
    ' The ThreadProc method is called when the thread starts.
    ' It loops ten times, writing to the console and yielding 
    ' the rest of its time slice each time, and then ends.
    Public Shared Sub ThreadProc()
        Dim i As Integer
        For i = 0 To 9
            Console.WriteLine("ThreadProc: {0}", i)
            ' Yield the rest of the time slice.
            Thread.Sleep(0)
        Next
    End Sub

    Public Shared Sub Main()
        Console.WriteLine("Main thread: Start a second thread.")
        ' The constructor for the Thread class requires a ThreadStart
 
        ' delegate.  The Visual Basic AddressOf operator creates this
        ' delegate for you.
        Dim t As New Thread(AddressOf
 ThreadProc)
        ' Start ThreadProc.  On a uniprocessor, the thread does not
 get 
        ' any processor time until the main thread yields.  Uncomment
 
        ' the Thread.Sleep that follows t.Start() to see the difference.
        t.Start()
        'Thread.Sleep(0)

        Dim i As Integer
        For i = 1 To 4
            Console.WriteLine("Main thread: Do some work.")
            Thread.Sleep(0)
        Next

        Console.WriteLine("Main thread: Call Join(), to wait until
 ThreadProc ends.")
        t.Join()
        Console.WriteLine("Main thread: ThreadProc.Join has returned.
  Press Enter to end program.")
        Console.ReadLine()
    End Sub
End Class
using System;
using System.Threading;

// Simple threading scenario:  Start a static method running
// on a second thread.
public class ThreadExample {
    // The ThreadProc method is called when the thread starts.
    // It loops ten times, writing to the console and yielding 
    // the rest of its time slice each time, and then ends.
    public static void ThreadProc()
 {
        for (int i = 0; i < 10; i++) {
            Console.WriteLine("ThreadProc: {0}", i);
            // Yield the rest of the time slice.
            Thread.Sleep(0);
        }
    }

    public static void Main()
 {
        Console.WriteLine("Main thread: Start a second thread.");
        // The constructor for the Thread class requires a ThreadStart
 
        // delegate that represents the method to be executed on the
 
        // thread.  C# simplifies the creation of this delegate.
        Thread t = new Thread(new ThreadStart(ThreadProc));
        // Start ThreadProc.  On a uniprocessor, the thread does not
 get 
        // any processor time until the main thread yields.  Uncomment
 
        // the Thread.Sleep that follows t.Start() to see the difference.
        t.Start();
        //Thread.Sleep(0);

        for (int i = 0; i < 4; i++) {
            Console.WriteLine("Main thread: Do some work.");
            Thread.Sleep(0);
        }

        Console.WriteLine("Main thread: Call Join(), to wait until ThreadProc
 ends.");
        t.Join();
        Console.WriteLine("Main thread: ThreadProc.Join has returned.  Press
 Enter to end program.");
        Console.ReadLine();
    }
}
// [C++]
// Compile using /clr option.
using namespace System;
using namespace System::Threading;

// Simple threading scenario:  Start a Shared method running
// on a second thread.
public ref class ThreadExample
{
public:

   // The ThreadProc method is called when the thread starts.
   // It loops ten times, writing to the console and yielding 
   // the rest of its time slice each time, and then ends.
   static void ThreadProc()
   {
      for ( int i = 0; i < 10; i++ )
      {
         Console::Write(  "ThreadProc: " );
         Console::WriteLine( i );
         
         // Yield the rest of the time slice.
         Thread::Sleep( 0 );

      }
   }

};

int main()
{
   Console::WriteLine( "Main thread: Start a second thread." );
   
   // Create the thread, passing a ThreadStart delegate that
   // represents the ThreadExample::ThreadProc method.  For a 
   // delegate representing a static method, no object is
   // required.
   Thread^ oThread = gcnew Thread( gcnew ThreadStart( &ThreadExample::ThreadProc
 ) );
   
   // Start the thread.  On a uniprocessor, the thread does not get
 
   // any processor time until the main thread yields.  Uncomment
   // the Thread.Sleep that follows t.Start() to see the difference.
   oThread->Start();
   
   //Thread::Sleep(0);
   for ( int i = 0; i < 4; i++ )
   {
      Console::WriteLine(  "Main thread: Do some work." );
      Thread::Sleep( 0 );

   }
   Console::WriteLine(  "Main thread: Call Join(), to wait until ThreadProc
 ends." );
   oThread->Join();
   Console::WriteLine(  "Main thread: ThreadProc.Join has returned.  Press Enter
 to end program." );
   Console::ReadLine();
   return 0;
}

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

// Simple threading scenario:  Start a static method running
// on a second thread.
public class ThreadExample
{
    // The ThreadProc method is called when the thread starts.
    // It loops ten times, writing to the console and yielding 
    // the rest of its time slice each time, and then ends.
    public static void ThreadProc()
 throws InterruptedException
    {
        for (int i = 0; i < 10; i++) {
            Console.WriteLine("ThreadProc: {0}", System.Convert.ToString(i));
            // Yield the rest of the time slice.
            Thread.sleep(0);
        }
    } //ThreadProc

    public static void main(String[]
 args) throws InterruptedException
    {
        Console.WriteLine("Main thread: Start a second thread.");

        // The constructor for the Thread class requires a ThreadStart
 
        // delegate that represents the method to be executed on the
 
        // thread.  J# simplifies the creation of this delegate.
        System.Threading.Thread t =
            new System.Threading.Thread(new
 ThreadStart(ThreadProc));

        // Start ThreadProc.  On a uniprocessor, the thread does not
 get 
        // any processor time until the main thread yields.  Uncomment
 
        // the Thread.Sleep that follows t.Start() to see the difference.
        t.Start();
        //Thread.Sleep(0);

        for (int i = 0; i < 4; i++) {
            Console.WriteLine("Main thread: Do some work.");
            Thread.sleep(0);
        }
        Console.WriteLine("Main thread: Call Join(), to wait until "
            + "ThreadProc ends.");
        t.Join();
        Console.WriteLine("Main thread: ThreadProc.Join has returned."
            + "  Press Enter to end program.");
        Console.ReadLine();
    } //main
} //ThreadExample

このコードによって、次のような出力が生成されます。

 [VB, C++, C#]
 Main thread: Start a second thread.
 Main thread: Do some work.
 ThreadProc: 0
 Main thread: Do some work.
 ThreadProc: 1
 Main thread: Do some work.
 ThreadProc: 2
 Main thread: Do some work.
 ThreadProc: 3
 Main thread: Call Join(), to wait until ThreadProc ends.
 ThreadProc: 4
 ThreadProc: 5
 ThreadProc: 6
 ThreadProc: 7
 ThreadProc: 8
 ThreadProc: 9
 Main thread: ThreadProc.Join has returned.  Press Enter to end program.
継承階層継承階層
System.Object
   System.Runtime.ConstrainedExecution.CriticalFinalizerObject
    System.Threading.Thread
スレッド セーフスレッド セーフ

この型は、マルチスレッド操作に対して安全です。

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

Thread コンストラクタ (ParameterizedThreadStart)

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

スレッドの開始時にオブジェクトをスレッドに渡すことを許可するデリゲートを指定して、Thread クラスの新しいインスタンスを初期化します。

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

Public Sub New ( _
    start As ParameterizedThreadStart _
)
Dim start As ParameterizedThreadStart

Dim instance As New Thread(start)
public Thread (
    ParameterizedThreadStart start
)
public:
Thread (
    ParameterizedThreadStart^ start
)
public Thread (
    ParameterizedThreadStart start
)
public function Thread (
    start : ParameterizedThreadStart
)

パラメータ

start

このスレッドが実行を開始するときに呼び出されるメソッドを表す ParameterizedThreadStart デリゲート。

例外例外
例外の種類条件

ArgumentNullException

start が null 参照 (Visual Basic では Nothing) です。

解説解説
使用例使用例

静的メソッドおよびインスタンス メソッドで ParameterizedThreadStart デリゲートを作成および使用するための構文のコード例を次に示します。

Imports System
Imports System.Threading

Public Class Work

    <MTAThread> _
    Shared Sub Main()
        ' To start a thread using a shared thread procedure, use
        ' the class name and method name when you create the 
        ' ParameterizedThreadStart delegate. Visual Basic expands
        ' the AddressOf expression to the appropriate delegate 
        ' creation syntax:
        '    New ParameterizedThreadStart(AddressOf Work.DoWork)
        '
        Dim newThread As New
 Thread(AddressOf Work.DoWork)
        
        ' Use the overload of the Start method that has a
        ' parameter of type Object. You can create an object that
        ' contains several pieces of data, or you can pass any 
        ' object or value type. The following code passes the
        ' integer value 42.
        '
        newThread.Start(42)

        ' To start a thread using an instance method for the thread
 
        ' procedure, use the instance variable and method name when
 
        ' you create the ParameterizedThreadStart delegate. Visual 
        ' Basic expands the AddressOf expression to the appropriate
 
        ' delegate creation syntax:
        '    New ParameterizedThreadStart(AddressOf w.DoMoreWork)
        '
        Dim w As New Work()
        newThread = New Thread(New ParameterizedThreadStart(AddressOf
 w.DoMoreWork))
        'newThread = New Thread(AddressOf w.DoMoreWork)
        
        ' Pass an object containing data for the thread.
        '
        newThread.Start("The answer.")
    End Sub
 
    Public Shared Sub DoWork(ByVal
 data As Object)
        Console.WriteLine("Static thread procedure. Data='{0}'",
 _
            data)
    End Sub

    Public Sub DoMoreWork(ByVal
 data As Object) 
        Console.WriteLine("Instance thread procedure. Data='{0}'",
 _
            data)
    End Sub
End Class

' This code example produces the following output (the order 
'   of the lines might vary):
'
'Static thread procedure. Data='42'
'Instance thread procedure. Data='The answer'
using System;
using System.Threading;

public class Work
{
    public static void Main()
    {
        // To start a thread using a shared thread procedure, use
        // the class name and method name when you create the 
        // ParameterizedThreadStart delegate.
        //
        Thread newThread = new Thread(
            new ParameterizedThreadStart(Work.DoWork));
        
        // Use the overload of the Start method that has a
        // parameter of type Object. You can create an object that
        // contains several pieces of data, or you can pass any 
        // reference type or value type. The following code passes
        // the integer value 42.
        //
        newThread.Start(42);

        // To start a thread using an instance method for the thread
 
        // procedure, use the instance variable and method name when
 
        // you create the ParameterizedThreadStart delegate.
        //
        Work w = new Work();
        newThread = new Thread(
            new ParameterizedThreadStart(w.DoMoreWork));
        
        // Pass an object containing data for the thread.
        //
        newThread.Start("The answer.");
    }
 
    public static void DoWork(object
 data)
    {
        Console.WriteLine("Static thread procedure. Data='{0}'",
            data);
    }

    public void DoMoreWork(object data)
    {
        Console.WriteLine("Instance thread procedure. Data='{0}'",
            data);
    }
}

/* This code example produces the following output (the order 
   of the lines might vary):

Static thread procedure. Data='42'
Instance thread procedure. Data='The answer'
*/
using namespace System;
using namespace System::Threading;

namespace SystemThreadingExample
{
    public ref class Work
    {
    public:
        void StartThreads()
        {
              
            // To start a thread using a shared thread procedure, use
            // the class name and method name when you create the 
            // ParameterizedThreadStart delegate.
            //    AddressOf Work.DoWork)
            //
            Thread^ newThread = gcnew 
                Thread(gcnew ParameterizedThreadStart(Work::DoWork));
              
            // Use the overload of the Start method that has a
            // parameter of type Object. You can create an object that
            // contains several pieces of data, or you can pass any
 
            // reference type or value type. The following code passes
            // the integer value 42.
            newThread->Start(42);
              
            // To start a thread using an instance method for the thread
 
            // procedure, use the instance variable and method name when
 
            // you create the ParameterizedThreadStart delegate.
            Work^ someWork = gcnew Work;
            newThread = 
                gcnew Thread(
                gcnew ParameterizedThreadStart(someWork, 
                &Work::DoMoreWork));
              
            // Pass an object containing data for the thread.
            //
            newThread->Start("The answer.");
        }

        static void DoWork(Object^ data)
        {
            Console::WriteLine("Static thread procedure. Data='{0}'", 
                data);
        }

        void DoMoreWork(Object^ data)
        {
            Console::WriteLine("Instance thread procedure. Data='{0}'",
 
                data);
        }
    };
}

//Entry point of example application
int main()
{
    SystemThreadingExample::Work^ samplework = 
        gcnew SystemThreadingExample::Work();
    samplework->StartThreads();
}

// This code example produces the following output (the order 
//   of the lines might vary):

// Static thread procedure. Data='42'
// Instance thread procedure. Data='The answer'

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

Thread コンストラクタ (ThreadStart, Int32)

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

Thread クラスの新しいインスタンスを初期化して、スレッドの最大スタック サイズを指定します。

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

Public Sub New ( _
    start As ThreadStart, _
    maxStackSize As Integer _
)
Dim start As ThreadStart
Dim maxStackSize As Integer

Dim instance As New Thread(start,
 maxStackSize)
public Thread (
    ThreadStart start,
    int maxStackSize
)
public:
Thread (
    ThreadStart^ start, 
    int maxStackSize
)
public Thread (
    ThreadStart start, 
    int maxStackSize
)
public function Thread (
    start : ThreadStart, 
    maxStackSize : int
)

パラメータ

start

このスレッドが実行を開始するときに呼び出されるメソッドを表す ThreadStart デリゲート。

maxStackSize

スレッドで使用する最大スタック サイズ。

例外例外
例外の種類条件

ArgumentNullException

start が null 参照 (Visual Basic では Nothing) です。

ArgumentOutOfRangeException

maxStackSize が 128K (131,072) 未満です。

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

Thread コンストラクタ (ParameterizedThreadStart, Int32)

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

Thread クラスの新しいインスタンスを初期化して、スレッドの開始時にオブジェクトをスレッドに渡すことを許可するデリゲートとこのスレッドの最大スタック サイズを指定します。

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

Public Sub New ( _
    start As ParameterizedThreadStart, _
    maxStackSize As Integer _
)
Dim start As ParameterizedThreadStart
Dim maxStackSize As Integer

Dim instance As New Thread(start,
 maxStackSize)
public Thread (
    ParameterizedThreadStart start,
    int maxStackSize
)
public:
Thread (
    ParameterizedThreadStart^ start, 
    int maxStackSize
)
public Thread (
    ParameterizedThreadStart start, 
    int maxStackSize
)
public function Thread (
    start : ParameterizedThreadStart, 
    maxStackSize : int
)

パラメータ

start

このスレッドが実行を開始するときに呼び出されるメソッドを表す ParameterizedThreadStart デリゲート。

maxStackSize

スレッドで使用する最大スタック サイズ。

例外例外
例外の種類条件

ArgumentNullException

start が null 参照 (Visual Basic では Nothing) です。

ArgumentOutOfRangeException

maxStackSize が 128K (131,072) 未満です。

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

Thread コンストラクタ


Thread コンストラクタ (ThreadStart)

Thread クラスの新しいインスタンスを初期化します。

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

Public Sub New ( _
    start As ThreadStart _
)
Dim start As ThreadStart

Dim instance As New Thread(start)
public Thread (
    ThreadStart start
)
public:
Thread (
    ThreadStart^ start
)
public Thread (
    ThreadStart start
)
public function Thread (
    start : ThreadStart
)

パラメータ

start

このスレッドが実行を開始するときに呼び出されるメソッドを表す ThreadStart デリゲート。

例外例外
例外の種類条件

ArgumentNullException

start パラメータが null 参照 (Visual Basic では Nothing) です。

解説解説
使用例使用例

静的メソッドを実行するスレッドを作成する方法を次のコード例に示します。

Imports System
Imports System.Threading

Public Class Test
    <MTAThread> _
    Shared Sub Main()
        Dim newThread As New
 Thread(AddressOf Work.DoWork)
        newThread.Start()
    End Sub
End Class

Public Class Work 

    Private Sub New()
    End Sub

    Shared Sub DoWork()
    End Sub

End Class
using System;
using System.Threading;

class Test
{
    static void Main() 
    {
        Thread newThread = 
            new Thread(new ThreadStart(Work.DoWork));
        newThread.Start();
    }
}

class Work 
{
    Work() {}

    public static void DoWork()
 {}
}
using namespace System;
using namespace System::Threading;
ref class Work
{
private:
   Work(){}


public:
   static void DoWork(){}

};

int main()
{
   Thread^ newThread = gcnew Thread( gcnew ThreadStart( &Work::DoWork ) );
   newThread->Start();
}

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

class Test
{
    public static void main(String[]
 args)
    {
        Thread newThread = new Thread(new ThreadStart(Work.DoWork));

        newThread.Start();
    } //main
} //Test

class Work
{
    Work()
    {
    } //Work

    public static void DoWork()
    {
    } //DoWork
} //Work

インスタンス メソッドを実行するスレッドを作成する方法を次のコード例に示します。

Imports System
Imports System.Threading

Public Class Test
    <MTAThread> _
    Shared Sub Main() 
        Dim threadWork As New
 Work()
        Dim newThread As New
 Thread(AddressOf threadWork.DoWork)
        newThread.Start()
    End Sub
End Class

Public Class Work

    Sub New()
    End Sub

    Sub DoWork() 
    End Sub

End Class
using System;
using System.Threading;

class Test
{
    static void Main() 
    {
        Work threadWork = new Work();
        Thread newThread = 
            new Thread(new ThreadStart(threadWork.DoWork));
        newThread.Start();
    }
}

class Work 
{
    public Work() {}

    public void DoWork() {}
}
using namespace System;
using namespace System::Threading;
ref class Work
{
public:
   Work(){}

   void DoWork(){}

};

int main()
{
   Work^ threadWork = gcnew Work;
   Thread^ newThread = gcnew Thread( gcnew ThreadStart( threadWork, &Work::DoWork
 ) );
   newThread->Start();
}

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

Thread プロパティ


Thread メソッド


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

  名前 説明
パブリック メソッド Abort オーバーロードされます。 このメソッドが呼び出された対象のスレッドで、そのスレッドの終了プロセスを開始する ThreadAbortException を発生させます。このメソッドを呼び出すと、通常、スレッドが終了します。
パブリック メソッド AllocateDataSlot 無名のデータ スロットをすべてのスレッドに割り当てます。
パブリック メソッド AllocateNamedDataSlot 名前付きのデータ スロットをすべてのスレッドに割り当てます。
パブリック メソッド BeginCriticalRegion スレッドの中止または処理されない例外の影響によりアプリケーション ドメイン内の他のタスクが悪影響を受ける可能性があるコード領域に実行が入ることをホストに通知します。
パブリック メソッド BeginThreadAffinity マネージ コードが現在のオペレーティング システムの物理スレッドの ID に依存する命令の実行を開始することをホストに通知します。
パブリック メソッド EndCriticalRegion スレッドの中止または処理されない例外の影響が現在のタスクだけに及ぶコード領域に実行が入ることをホストに通知します。
パブリック メソッド EndThreadAffinity マネージ コードが現在のオペレーティング システムの物理スレッドの ID に依存する命令の実行を完了したことをホストに通知します。
パブリック メソッド Equals  オーバーロードされます。 2 つの Object インスタンスが等しいかどうかを判断します。 ( Object から継承されます。)
パブリック メソッド FreeNamedDataSlot プロセス内のすべてのスレッドに関して、名前とスロットの関連付けを解除します。
パブリック メソッド GetApartmentState アパートメント状態を示す ApartmentState 値を返します。
パブリック メソッド GetCompressedStack 現在のスレッドのスタックをキャプチャするために使用できる CompressedStack オブジェクトを返します。
パブリック メソッド GetData 現在のスレッドの現在のドメイン内で指定した現在のスレッドのスロットから値を取得します。
パブリック メソッド GetDomain 現在のスレッドが実行されている現在のドメインを返します。
パブリック メソッド GetDomainID 一意のアプリケーション ドメイン識別子を返します。
パブリック メソッド GetHashCode オーバーライドされます。 現在のスレッドのハッシュ コードを返します。
パブリック メソッド GetNamedDataSlot 名前付きデータ スロットを検索します。
パブリック メソッド GetType  現在のインスタンスの Type を取得します。 ( Object から継承されます。)
パブリック メソッド Interrupt WaitSleepJoin スレッド状態のスレッドを中断します。
パブリック メソッド Join オーバーロードされます。 スレッドが終了するまで、呼び出し元のスレッドをブロックします。
パブリック メソッド MemoryBarrier メモリを同期します。結果として、現在のスレッドを実行しているプロセッサで、キャッシュ メモリの内容がメイン メモリにフラッシュされます。
パブリック メソッド ReferenceEquals  指定した複数の Object インスタンスが同一かどうかを判断します。 ( Object から継承されます。)
パブリック メソッド ResetAbort 現在のスレッドに対して要求された Abort をキャンセルします。
パブリック メソッド Resume 中断されたスレッドを再開します。
パブリック メソッド SetApartmentState スレッドを開始する前にスレッドのアパートメント状態を設定します。
パブリック メソッド SetCompressedStack キャプチャした CompressedStack を現在のスレッドに適用します。
パブリック メソッド SetData 現在実行中のスレッド上にある指定されたスロット内のデータを、そのスレッドの現在のドメインに設定します。
パブリック メソッド Sleep オーバーロードされます。 指定したミリ秒数の間現在のスレッドをブロックします。
パブリック メソッド SpinWait スレッドを iterations パラメータで定義した時間の間待機させます。
パブリック メソッド Start オーバーロードされます。 スレッドの実行をスケジュールします。
パブリック メソッド Suspend スレッドを中断します。スレッドが既に中断されている場合は無効です。
パブリック メソッド ToString  現在の Object を表す String を返します。 ( Object から継承されます。)
パブリック メソッド TrySetApartmentState スレッドを開始する前にスレッドのアパートメント状態を設定します。
パブリック メソッド VolatileRead オーバーロードされます。 フィールドの値を読み取ります。この値は、プロセッサの数やプロセッサ キャッシュの状態にかかわらず、コンピュータ内のいずれかのプロセッサによって書き込まれた最新の値です。
パブリック メソッド VolatileWrite オーバーロードされます。 値をフィールドにすぐに書き込みます。値はコンピュータ内のすべてのプロセッサに対して可視になります。
明示的インターフェイスの実装明示的インターフェイスの実装
  名前 説明
インターフェイスの明示的な実装 System.Runtime.InteropServices._Thread.GetIDsOfNames 一連の名前を対応する一連のディスパッチ識別子に割り当てます。
インターフェイスの明示的な実装 System.Runtime.InteropServices._Thread.GetTypeInfo オブジェクトの型情報を取得します。その後は、インターフェイスの型情報の取得に使用できます。
インターフェイスの明示的な実装 System.Runtime.InteropServices._Thread.GetTypeInfoCount オブジェクトが提供する型情報インターフェイスの数 (0 または 1) を取得します。
インターフェイスの明示的な実装 System.Runtime.InteropServices._Thread.Invoke オブジェクトが公開するプロパティおよびメソッドにアクセスできるようにします。
参照参照

関連項目

Thread クラス
System.Threading 名前空間

その他の技術情報

スレッドおよびスレッド処理
スレッドの使用とスレッド処理

Thread メンバ

スレッドを作成および制御し、そのスレッドの優先順位の設定およびステータスの取得を行います。

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


パブリック コンストラクタパブリック コンストラクタ
パブリック プロパティパブリック プロパティ
パブリック メソッドパブリック メソッド
  名前 説明
パブリック メソッド Abort オーバーロードされます。 このメソッドが呼び出された対象のスレッドで、そのスレッドの終了プロセスを開始する ThreadAbortException を発生させます。このメソッドを呼び出すと、通常、スレッドが終了します。
パブリック メソッド AllocateDataSlot 無名のデータ スロットをすべてのスレッドに割り当てます。
パブリック メソッド AllocateNamedDataSlot 名前付きのデータ スロットをすべてのスレッドに割り当てます。
パブリック メソッド BeginCriticalRegion スレッドの中止または処理されない例外の影響によりアプリケーション ドメイン内の他のタスクが悪影響を受ける可能性があるコード領域に実行が入ることをホストに通知します。
パブリック メソッド BeginThreadAffinity マネージ コードが現在のオペレーティング システムの物理スレッドの ID に依存する命令の実行を開始することをホストに通知します。
パブリック メソッド EndCriticalRegion スレッドの中止または処理されない例外の影響が現在のタスクだけに及ぶコード領域に実行が入ることをホストに通知します。
パブリック メソッド EndThreadAffinity マネージ コードが現在のオペレーティング システムの物理スレッドの ID に依存する命令の実行を完了したことをホストに通知します。
パブリック メソッド Equals  オーバーロードされます。 2 つの Object インスタンスが等しいかどうかを判断します。 (Object から継承されます。)
パブリック メソッド FreeNamedDataSlot プロセス内のすべてのスレッドに関して、名前とスロットの関連付けを解除します。
パブリック メソッド GetApartmentState アパートメント状態を示す ApartmentState 値を返します。
パブリック メソッド GetCompressedStack 現在のスレッドのスタックをキャプチャするために使用できる CompressedStack オブジェクトを返します。
パブリック メソッド GetData 現在のスレッドの現在のドメイン内で指定した現在のスレッドのスロットから値を取得します。
パブリック メソッド GetDomain 現在のスレッドが実行されている現在のドメインを返します。
パブリック メソッド GetDomainID 一意のアプリケーション ドメイン識別子を返します。
パブリック メソッド GetHashCode オーバーライドされます。 現在のスレッドのハッシュ コードを返します。
パブリック メソッド GetNamedDataSlot 名前付きデータ スロットを検索します。
パブリック メソッド GetType  現在のインスタンスの Type を取得します。 (Object から継承されます。)
パブリック メソッド Interrupt WaitSleepJoin スレッド状態のスレッドを中断します。
パブリック メソッド Join オーバーロードされます。 スレッドが終了するまで、呼び出し元のスレッドをブロックします。
パブリック メソッド MemoryBarrier メモリを同期します。結果として、現在のスレッドを実行しているプロセッサで、キャッシュ メモリの内容がメイン メモリにフラッシュされます。
パブリック メソッド ReferenceEquals  指定した複数の Object インスタンスが同一かどうかを判断します。 (Object から継承されます。)
パブリック メソッド ResetAbort 現在のスレッドに対して要求された Abort をキャンセルします。
パブリック メソッド Resume 中断されたスレッドを再開します。
パブリック メソッド SetApartmentState スレッドを開始する前にスレッドのアパートメント状態を設定します。
パブリック メソッド SetCompressedStack キャプチャした CompressedStack を現在のスレッドに適用します。
パブリック メソッド SetData 現在実行中のスレッド上にある指定されたスロット内のデータを、そのスレッドの現在のドメインに設定します。
パブリック メソッド Sleep オーバーロードされます。 指定したミリ秒数の間現在のスレッドをブロックします。
パブリック メソッド SpinWait スレッドを iterations パラメータで定義した時間の間待機させます。
パブリック メソッド Start オーバーロードされます。 スレッドの実行をスケジュールします。
パブリック メソッド Suspend スレッドを中断します。スレッドが既に中断されている場合は無効です。
パブリック メソッド ToString  現在の Object を表す String を返します。 (Object から継承されます。)
パブリック メソッド TrySetApartmentState スレッドを開始する前にスレッドのアパートメント状態を設定します。
パブリック メソッド VolatileRead オーバーロードされます。 フィールドの値を読み取ります。この値は、プロセッサの数やプロセッサ キャッシュの状態にかかわらず、コンピュータ内のいずれかのプロセッサによって書き込まれた最新の値です。
パブリック メソッド VolatileWrite オーバーロードされます。 値をフィールドにすぐに書き込みます。値はコンピュータ内のすべてのプロセッサに対して可視になります。
明示的インターフェイスの実装明示的インターフェイスの実装
  名前 説明
インターフェイスの明示的な実装 System.Runtime.InteropServices._Thread.GetIDsOfNames 一連の名前を対応する一連のディスパッチ識別子に割り当てます。
インターフェイスの明示的な実装 System.Runtime.InteropServices._Thread.GetTypeInfo オブジェクトの型情報を取得します。その後は、インターフェイスの型情報の取得に使用できます。
インターフェイスの明示的な実装 System.Runtime.InteropServices._Thread.GetTypeInfoCount オブジェクトが提供する型情報インターフェイスの数 (0 または 1) を取得します。
インターフェイスの明示的な実装 System.Runtime.InteropServices._Thread.Invoke オブジェクトが公開するプロパティおよびメソッドにアクセスできるようにします。
参照参照

関連項目

Thread クラス
System.Threading 名前空間

その他の技術情報

スレッドおよびスレッド処理
スレッドの使用とスレッド処理

_Thread インターフェイス

メモ : このインターフェイスは、.NET Framework version 2.0 で新しく追加されたものです。

System.Threading.Thread クラスをアンマネージ コードに公開します。

 

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

<InterfaceTypeAttribute(ComInterfaceType.InterfaceIsIUnknown)> _
<ComVisibleAttribute(True)> _
<GuidAttribute("C281C7F1-4AA9-3517-961A-463CFED57E75")>
 _
<CLSCompliantAttribute(False)> _
Public Interface _Thread
[InterfaceTypeAttribute(ComInterfaceType.InterfaceIsIUnknown)] 
[ComVisibleAttribute(true)] 
[GuidAttribute("C281C7F1-4AA9-3517-961A-463CFED57E75")] 
[CLSCompliantAttribute(false)] 
public interface _Thread
[InterfaceTypeAttribute(ComInterfaceType::InterfaceIsIUnknown)] 
[ComVisibleAttribute(true)] 
[GuidAttribute(L"C281C7F1-4AA9-3517-961A-463CFED57E75")] 
[CLSCompliantAttribute(false)] 
public interface class _Thread
/** @attribute InterfaceTypeAttribute(ComInterfaceType.InterfaceIsIUnknown) */ 
/** @attribute ComVisibleAttribute(true) */ 
/** @attribute GuidAttribute("C281C7F1-4AA9-3517-961A-463CFED57E75") */
 
/** @attribute CLSCompliantAttribute(false) */ 
public interface _Thread
InterfaceTypeAttribute(ComInterfaceType.InterfaceIsIUnknown) 
ComVisibleAttribute(true) 
GuidAttribute("C281C7F1-4AA9-3517-961A-463CFED57E75") 
CLSCompliantAttribute(false) 
public interface _Thread
解説解説
プラットフォームプラットフォーム
バージョン情報バージョン情報
参照参照
関連項目
_Thread メンバ
System.Runtime.InteropServices 名前空間

_Thread メソッド


_Thread メンバ



このページでは「.NET Framework クラス ライブラリ リファレンス」からThreadを検索した結果を表示しています。
Weblioに収録されているすべての辞書からThreadを検索する場合は、下記のリンクをクリックしてください。
 全ての辞書からThread を検索

英和和英テキスト翻訳

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

辞書ショートカット

すべての辞書の索引

「Thread」の関連用語

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

   

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



Threadのページの著作権

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

©2026 GRAS Group, Inc.RSS