Practices for Foreground/Background threads in .NET

433 views Asked by At

I work with in-house legacy communication framework which exposes some high level abstractions. These abstractions are wrappers with some logic around .NET threads. When I looked at code I've noticed that some abstractions are wrappers around foreground threads while others are wrappers around background threads.

The sad thing is that I don't see any logic why in some cases foreground threads are used and background in other cases.

Are there any guidelines or patterns & practices when it's better to choose one over another on server side and client side (I believe there should be some difference)?

Any examples from your own professional experience when it was crucial or just a good solution to prefer one over another?

1

There are 1 answers

1
George Johnston On

Straight from MSDN

A managed thread is either a background thread or a foreground thread. Background threads are identical to foreground threads with one exception: a background thread does not keep the managed execution environment running. Once all foreground threads have been stopped in a managed process (where the .exe file is a managed assembly), the system stops all background threads and shuts down.