Help with Task parallel library usage?

I don't know if this is causing execution to stop, but perhaps it's because you're closing over the loop variable here: DoSomeWork(someValue)) You need to create a local variable and assign someValue to it, and then use that local variable, as is described in my linked question, like so: foreach(var someValue in aCollection) { var localCopy = someValue; var t = Task.Factory. StartNew(() => DoSomeWork(localCopy)); tasks. Add(t); } Again, I've no idea if that is the problem to your deadlock issue, but that is one issue that will most likely cause problems.

I don't know if this is causing execution to stop, but perhaps it's because you're closing over the loop variable here: DoSomeWork(someValue)); You need to create a local variable and assign someValue to it, and then use that local variable, as is described in my linked question, like so: foreach(var someValue in aCollection) { var localCopy = someValue; var t = Task.Factory. StartNew(() => DoSomeWork(localCopy)); tasks. Add(t); } Again, I've no idea if that is the problem to your deadlock issue, but that is one issue that will most likely cause problems.

Yes. That was the issue. Thanks.

+1. How about the sequence thing? Any idea?

– stackoverflowuser Feb 8 at 0:00 1 You can just use a for loop in conjunction with this overload of Task. The object passed in gets assigned to AsyncState, and can be anything, it's completely arbitrary. In this case, just pass in the iterator variable (i) and retrieve it when WaitAll exits.

– nasufara Feb 8 at 0:05 An example would really help. Thanks. – stackoverflowuser Feb 8 at 1:31 Wait, your second question, I read it more carefully, do you mean you want to know which task was started first, or which one ended first?

– nasufara Feb 8 at 1:54.

I am trying to schedule a function call for a sequence of items using Task parallel library. For the first approach it executes once and then stops. I am not sure if its overwriting the reference or something.

I cant really gove you an answer,but what I can give you is a way to a solution, that is you have to find the anglde that you relate to or peaks your interest. A good paper is one that people get drawn into because it reaches them ln some way.As for me WW11 to me, I think of the holocaust and the effect it had on the survivors, their families and those who stood by and did nothing until it was too late.

Related Questions