4

Is it possible to recognize a thread is a worker or an I/O.

I know the code

Thread.CurrentThread.IsThreadPoolThread

this code is to show whether it is a thread pool thread, but it seems no method to show if it's a worker thread.

How can I check it? Is it possible?

roast_soul
  • 3,554
  • 7
  • 36
  • 73
  • http://stackoverflow.com/questions/2099947/simple-description-of-worker-and-i-o-threads-in-net - `There is really no technical difference between 'worker thread' and 'I/O thread'` in Dynamix AX there is something called `.isWorkerThread` but not sure If I am missing any context apart from that `:)` – Tats_innit Aug 05 '14 at 02:48
  • I/O thread is a thread that executes I/O callbacks. So any asynchronous I/O callbacks will be processed on ThreadPool I/O threads. If you need to know on which thread you're running outside of the callback method itself, you might need a redesign :) At the very least, you could pass that information as a parameter if needed. What's the problem you're trying to solve? – Luaan Aug 05 '14 at 07:44
  • @Luaan, thank you for your answer. I just test some code, to see which kind of thread handle the callback. – roast_soul Aug 05 '14 at 11:59
  • 1
    Well, do note that separating threadpool threads into worker and I/O is an implementation detail, mostly. It can change at any time, so you shouldn't really rely on the specifics - new pools can be added at any time, and the existing merged as well. Remember the patterns instead - in an asynchronous callback, you only want to do as little work as reasonable, if you need to do more than a bit, schedule the work further (either using `ThreadPool.QueueWorkerItem`, `Task.Run` or some other mechanism if you have your own scheduling for example). – Luaan Aug 05 '14 at 12:03

1 Answers1

1

There is no difference between the threads except for the pool they were/are in as you can read here: Simple description of worker and I/O threads in .NET

A thread has no knowledge about the pool that it came from. So this is not possible.

Community
  • 1
  • 1
Emond
  • 50,210
  • 11
  • 84
  • 115