If you're doing I/O-based operations, async
and await
are great. In a Win32 service, you don't have a SynchronizationContext
, so all your continuations end up as tasks on the thread pool, which does a great job of load balancing. (Remember, Task
!= Thread
; hundreds or even thousands of Task
s are just fine).
If you're doing CPU-based operations, then I'd recommend the Task Parallel Library. In particular, the Parallel
type. PLINQ is sometimes easier to use but it will assume that it can use all cores by default; since you're doing a Win32 service you'd want to be a bit "nicer" (to use Linux terminology).
TPL Dataflow is a great library that takes async
/await
to the next level. It does sound like your solution could use a TPL Dataflow-based approach. You can also "mix and match" between async
, TPL, and TPL Dataflow quite nicely.