C# parallel coding

Posted in C#, on 5/4/2014

Use C# Parallel would do task in parallel, which could run jobs faster and the code is simple to use.

If you have to call 2000 api via internet in a job schedular for some kind of reason. For example, you could use this way to imprement the application, which call 2000 times api in parallel.

Parallel.ForEach(dataList, data =>

This will run DoYourWorkInParallel(data) with different process, if you have super computer, idealy it will run everything at the same time. Cool!

I don't have a super computer, so this call will kill your computer or you will get some network error. 

One of the choice is, you could write

Keep running your task until meet some kind of rule you defined.

while (YourRuleIsTrue)

Windows Service App to Watch and keep Run

Or, write your application and deploy to windows service, so you can control when, how to call the api.