ParameterizedThreadStart デリゲート
アセンブリ: mscorlib (mscorlib.dll 内)

/** @delegate */ /** @attribute ComVisibleAttribute(false) */ public delegate void ParameterizedThreadStart ( Object obj )

マネージ スレッドを作成すると、そのスレッドで実行するメソッドが、Thread コンストラクタに渡される ThreadStart デリゲートまたは ParameterizedThreadStart デリゲートで表されます。スレッドは System.Threading.Thread.Start メソッドが呼び出されるまで実行を開始しません。実行は、ThreadStart または ParameterizedThreadStart デリゲートで表されるメソッドの最初の行から開始されます。
![]() |
---|
Visual Basic および C# のユーザーは、スレッドを作成するときに ThreadStart または ParameterizedThreadStart デリゲート コンストラクタを省略できます。Visual Basic では、メソッドを Thread コンストラクタに渡すときに、Dim t As New Thread(AddressOf ThreadProc) のように AddressOf 演算子を使用します。C# では、単純にスレッド プロシージャの名前を指定します。コンパイラにより、適切なデリゲート コンストラクタが選択されます。 |
![]() |
---|
C++ でインスタンス メソッドの ParameterizedThreadStart デリゲートを作成すると、コンストラクタの最初のパラメータはインスタンス変数になります。静的メソッドの場合、最初のパラメータは 0 になります。静的メソッドの場合、デリゲート コンストラクタに必要なパラメータは 1 つだけであり、クラス名で修飾されたコールバック メソッドのアドレスです。 |
ParameterizedThreadStart デリゲートおよび Thread.Start(Object) メソッドをオーバーロードするとデータをスレッド プロシージャに簡単に渡せるようになりますが、この方法はすべてのオブジェクトを Thread.Start(Object) に渡すことができるため、タイプ セーフではありません。より信頼性の高い方法でスレッド プロシージャにデータを渡すには、スレッド プロシージャとデータ フィールドの両方をワーカー オブジェクトに格納します。詳細については、「スレッドを作成し、開始時にデータを渡す」を参照してください。

静的メソッドおよびインスタンス メソッドで 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'

Windows 98, Windows 2000 SP4, Windows Millennium Edition, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition
開発プラットフォームの中には、.NET Framework によってサポートされていないバージョンがあります。サポートされているバージョンについては、「システム要件」を参照してください。


Weblioに収録されているすべての辞書からParameterizedThreadStart デリゲートを検索する場合は、下記のリンクをクリックしてください。

- ParameterizedThreadStart デリゲートのページへのリンク