ParameterizedThreadStart デリゲートとは? わかりやすく解説

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

ParameterizedThreadStart デリゲート

メモ : このデリゲートは、.NET Framework version 2.0新しく追加されたものです。

Thread実行するメソッド表します

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

<ComVisibleAttribute(False)> _
Public Delegate Sub ParameterizedThreadStart
 ( _
    obj As Object _
)
Dim instance As New ParameterizedThreadStart(AddressOf
 HandlerMethod)
[ComVisibleAttribute(false)] 
public delegate void ParameterizedThreadStart
 (
    Object obj
)
[ComVisibleAttribute(false)] 
public delegate void ParameterizedThreadStart
 (
    Object^ obj
)
/** @delegate */
/** @attribute ComVisibleAttribute(false) */ 
public delegate void ParameterizedThreadStart
 (
    Object obj
)
JScript では、デリゲート使用できますが、新規に宣言することはできません。

パラメータ

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# では、単純にスレッド プロシージャの名前を指定しますコンパイラにより、適切なデリゲート コンストラクタ選択されます。

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'

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


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

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

辞書ショートカット

すべての辞書の索引

「ParameterizedThreadStart デリゲート」の関連用語

ParameterizedThreadStart デリゲートのお隣キーワード
検索ランキング

   

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



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

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

©2024 GRAS Group, Inc.RSS