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

startnull 参照 (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

startnull 参照 (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

startnull 参照 (Visual Basic では Nothing) です。

ArgumentOutOfRangeException

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

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

Thread コンストラクタ


Thread コンストラクタ (ThreadStart)

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

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

Public Sub New ( _
    start As ThreadStart _
)
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();
}

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


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

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

辞書ショートカット

すべての辞書の索引

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

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

   

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



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

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

©2024 GRAS Group, Inc.RSS