Ok, playing with .Net 4.0 Parellel Extensions in System.Threading.Tasks. I find what seems to be strange behavior, but I believe that I am doing something wrong. I have an interface and a couple of implementing clans, they are just for that.
interface IParallelPipe
{
void Process(ref BlockingCollection<Stream> stream, long stageId);
}
class A:IParallelPipe
{
public void Process(ref BlockingCollection<Stream> stream, long stageId)
{
}
}
class B:IParallelPipe
{
public void Process(ref BlockingCollection<Stream> stream, long stageId)
{
}
}
Then I have a class that runs everything on them. This is where the problem arises. I essentially get information about what the implementing class calls from the passed type, and then calls the factory to create it, and then create a task with it and start it. Shown here:
BlockingCollection<Stream> bcs = new BlockingCollection<Stream>();
foreach (Stage s in pipeline.Stages)
{
IParallelPipe p = (IParallelPipe)Factory.GetPipe(s.type);
Task.Factory.StartNew(() => p.Process(ref bcs, s.id));
}
.Stages : , A, B. , te, p . B , A.Process(...). stageId , (.. stageIds).
, , , - :
BlockingCollection<Stream> bcs = new BlockingCollection<Stream>();
A a = null;
B b = null;
foreach (Stage s in pipeline.Stages)
{
IParallelPipe p = (IParallelPipe)Factory.GetPipe(s.type);
if(p is A)
a = p;
else
b = p;
}
Task.Factory.StartNew(() => a.Process(ref bcs, idThatINeed));
Task.Factory.StartNew(() => b.Process(ref bcs, idThatINeed));
!
???