简体   繁体   中英

Is this a good use case for Task Parallel Library?

I have a situation and need some advice. I'm calling Twitter to get retweets, replies, likes, and stuff like that. Twitter, of course, rates limit your calls so I need to pace out my calls. And since I do not want to wait for a long time if one user is locked up because I still want to continue getting engagements for other users, I thought I should use multiple threads. As an experiment, I tried Parallel task library something like:

Task.Factory.StartNew(() => Parallel.ForEach<BatchJob>(jobsToProcess, job =>
{
    //call Twitter here
}); 

From testing, it seems that this was eating up a lot of CPU and froze the whole system. My question is: Is this a situation where using Parallel task will fit? I do not need to wait for one task to finish to start another. They all can run at the same time. In other words, the tasks do not depend on each other.

If it is in a context of an webApp, your call will be lost. Please view an session of build 2013 where they explain why. If It is a desktop application, it should work as long as you use "dispatcher" object to update your visual.

I don't like to use "task.factory", it's just me, but I prefer the syntax "new task (() => {...})

Edit : no parallel task won't change a thing.

It's meant as comment, can't find a link for comment

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM