views:

133

answers:

1

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  A: 

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:

Mark Byers
+1, `BeginRead` is the best way to handle this as it uses IOCP.
Darin Dimitrov