Reputation: 227
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.
Upvotes: 1
Views: 307
Reputation: 1298
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
Upvotes: 1