Can I use too many background worker threads?

↘锁芯ラ 提交于 2019-12-10 19:44:55

问题


Each time my code needs to talk to the network or a database I use a backgroundworker, can I use too many, what is the correct way of doing these tasks?

If I don't use a background worker the gui locks up if a remote host is down etc so using a backgroundworker is the only way I know to fix this.

I'm self taught so I'm learning as I go along, thanks to all who answer.


回答1:


Yes, you can use too many. BackgroundWorker uses threads from the threadpool, so if you start too many (simultaneously) you will exhaust the thread pool.

Background worker is meant for long running operations, not short operations that might occasionally block. Use non-blocking I/O instead:

  • BeginConnect
  • BeginRead


来源:https://stackoverflow.com/questions/2198907/can-i-use-too-many-background-worker-threads

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!