Using threads correctly

G

Guest

Hi guys,

Whenever i need to use threads in my apps, i always
have the same problem of choosing the right kind of
threads to create.
I never know whether to create threads by using:
1) The Thread class, which may create a new os thread
2) A delegate, which uses a thread from the thread pool
3) The ThreadPool, which uses the thread pool as well

Can anyone please shed some light on this subject?

Thanks,
Avi
 
J

Jon Skeet [C# MVP]

Avi Shilon said:
Whenever i need to use threads in my apps, i always
have the same problem of choosing the right kind of
threads to create.
I never know whether to create threads by using:
1) The Thread class, which may create a new os thread
2) A delegate, which uses a thread from the thread pool
3) The ThreadPool, which uses the thread pool as well

Can anyone please shed some light on this subject?

Or 4) using a thread pool other than the system one.

I would suggest only using the system ThreadPool for short operations
which definitely won't need to use the threadpool themselves - it's
easy to deadlock, as the framework libraries don't say which method
calls block on other thread pool threads.

I would usually advocate a custom thread pool or a new thread.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top