I'm not sure this is what the OP is asking. Other apps and programs on a PC may be set up to parallelize workloads, but he's asking about how to do this with his applications that he develops.
What you are looking for, OP, is threading. This can be done several ways in C#, including manually declaring and managing threads yourself (System.Threading.Thread), using the Threadpool, or using a Background worker.
It's difficult to describe which one would be best because you haven't described a specific use case that you're trying to run in parallel. Manually managing threads is generally considered less clean than using the Threadpool, but may make sense in some situations. Threadpool is probably the most flexible and versitle way to parallelize a workload, while a Background worker will be the easiest. I also tend to like them the least.
Again, it's hard to say which you should choose, and it's even harder to begin to describe the nuances that threaded programing will introduce; it's another method entirely to describe how you can know what work to break up into separate threads, or how you can most effectively use threading. Just know that in most cases, if you want your code to take advantage of multiple CPU cores, it needs to split up the heavy work into separate threads.
No comments:
Post a Comment