c# run thread in threadpool

This is the way of running thread in ThreadPool
1 only for 4.5 Framework
Task.Run(() => doStuff("hello world"));
Task.Factory.StartNew(() => doStuff("hello world"));
ThreadPool.QueueUserWorkItem(a => doStuff("hello world"));
void Example()
    // Hook up the ProcessFile method to the ThreadPool.
    // Note: 'a' is an argument name. Read more on arguments.
    ThreadPool.QueueUserWorkItem(new WaitCallback(ProcessFile), a);

private void ProcessFile(object a)
    // I was hooked up to the ThreadPool by WaitCallback.

No comments:

Post a Comment