不是非此即彼的场景。如下混合使用CCR+TPL的代码说明问题:
It's not an either/or scenario.You can intermix CCR and TPL code like this, here is a Parallel.For inside of a Receive delegate:
usingSystem;
usingSystem.Threading;
usingSystem.Threading.Tasks;
usingMicrosoft.Ccr.Core;
namespaceDemo
{
publicclassProgram
{
publicstaticvoidMain(string[] args)
{
Dispatcher dispatcher =newDispatcher();
DispatcherQueue taskQueue =newDispatcherQueue("Demo", dispatcher);
Port<int> portInt =newPort<int>();
portInt.Post(Int32.Parse(args[0]));
Arbiter.Activate(
taskQueue,
portInt.Receive(delegate(int count)
{
Parallel.For(0, count, i =>
{
Console.Write(i.ToString()+" ");
});
}
));
}
}
}