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

WaitCallback デリゲート

スレッド プール スレッド実行するコールバック メソッド表します

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

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

パラメータ

state

コールバック メソッド使用する情報格納したオブジェクト

解説解説
使用例使用例
Imports System
Imports System.Threading

Public Class Example

    <MTAThread> _
    Public Shared Sub Main()
        ' Queue the task.
        ThreadPool.QueueUserWorkItem( _
            New WaitCallback(AddressOf ThreadProc)
 _
            )
        ' Note that you do not have to create the WaitCallback delegate
        ' explicitly in Visual Basic.  The following line also queues
 
        ' the task:
        'ThreadPool.QueueUserWorkItem(AddressOf ThreadProc)
        
        Console.WriteLine("Main thread does some work, then sleeps.")
        ' If you comment out the Sleep, the main thread exits before
        ' the thread pool task runs.  The thread pool uses background
        ' threads, which do not keep the application running.  (This
        ' is a simple example of a race condition.)
        Thread.Sleep(1000)

        Console.WriteLine("Main thread exits.")
    End Sub

    ' This thread procedure performs the task.
    Shared Sub ThreadProc(stateInfo As
 Object)
        ' No state object was passed to QueueUserWorkItem, so 
        ' stateInfo is null.
        Console.WriteLine("Hello from the thread pool.")
    End Sub
End Class
using System;
using System.Threading;
public class Example {
    public static void Main()
 {
        // Queue the task.
        ThreadPool.QueueUserWorkItem(new WaitCallback(ThreadProc));
        
        Console.WriteLine("Main thread does some work, then sleeps.");
        // If you comment out the Sleep, the main thread exits before
        // the thread pool task runs.  The thread pool uses background
        // threads, which do not keep the application running.  (This
        // is a simple example of a race condition.)
        Thread.Sleep(1000);

        Console.WriteLine("Main thread exits.");
    }

    // This thread procedure performs the task.
    static void ThreadProc(Object stateInfo)
 {
        // No state object was passed to QueueUserWorkItem, so 
        // stateInfo is null.
        Console.WriteLine("Hello from the thread pool.");
    }
}
using namespace System;
using namespace System::Threading;
ref class Example
{
public:

   // This thread procedure performs the task.
   static void ThreadProc( Object^ stateInfo
 )
   {
      
      // No state object was passed to QueueUserWorkItem, so 
      // stateInfo is 0.
      Console::WriteLine( "Hello from the thread pool." );
   }

};

int main()
{
   
   // Queue the task.
   ThreadPool::QueueUserWorkItem( gcnew WaitCallback( Example::ThreadProc ) );
   Console::WriteLine( "Main thread does some work, then sleeps." );
   
   // If you comment out the Sleep, the main thread exits before
   // the thread pool task runs.  The thread pool uses background
   // threads, which do not keep the application running.  (This
   // is a simple example of a race condition.)
   Thread::Sleep( 1000 );
   Console::WriteLine( "Main thread exits." );
   return 0;
}

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

public class Example
{
    public static void main(String[]
 args)
    {
        // Queue the task.
        ThreadPool.QueueUserWorkItem(new WaitCallback(ThreadProc));
        Console.WriteLine("Main thread does some work, then sleeps.");

        // If you comment out the Sleep, the main thread exits before
        // the thread pool task runs.  The thread pool uses background
        // threads, which do not keep the application running.  (This
        // is a simple example of a race condition.)
        Thread.Sleep(1000);
        Console.WriteLine("Main thread exits.");
    } //main

    // This thread procedure performs the task.
    static void ThreadProc(Object stateInfo)
    {
        // No state object was passed to QueueUserWorkItem, so 
        // stateInfo is null.
        Console.WriteLine("Hello from the thread pool.");
    } //ThreadProc
} //Example
プラットフォームプラットフォーム
バージョン情報バージョン情報
参照参照



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

辞書ショートカット

すべての辞書の索引

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

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

   

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



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

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

©2024 GRAS Group, Inc.RSS