MaxMessages compare with unlinkAfterOne in TPL data flow

4 באפריל 2012

תגיות: , , , ,
תגובה אחת

In the Updated TPL DataFlow CTP that was introduced in September 2011 they made a nice change in the method LinkTo, that connects blocks together like Broadcast block and a Actionblock. They remove the Boolean in the method parameter that represented the parameter for UnLinkAfterOne and change it with a class DataflowLinkOptions with a property called MaxMessages. The difference between the UnLinkAfterOne and the MaxMessages in the DataflowLinkOptions are really nice.

In the old TPL data flow CTP, way the if you would have set the UnLinkAfterOne into true, if a message would be propagated between the 2 blocks, the link between them would have been close and no more messages would have been transfer from the source block to the target block, and if UnLinkAfterOne was false the link would have been stayed open not matter how many massages would have been transferred though the link.

In the new TPL data flow CTP, the name of the property was changed from UnLinkAfterOne into MaxMessages and the type changed as well. MaxMessages values now means:

  • –1 : The same as UnLinkAfterOne = false, the link will stay open from the source block to the target block no matter how many messages transferred between them.
  • 1 : The same as UnLinkAfterOne = true, the Massage will be closed from the source block after propagating one message the target block.
  • > 1 : Here is the big change – you can set a number above 1 that will represent how many messaged will be transferred from the source block to the target block until the link between them will be closed. IF you got a target block that can only handle few messages but more then 1, this a nice solution for you.

Here are some C# codes in the old TPL Dataflow CTP comare with the new TPL Dataflow CTP:

//Don't close the link after the a message had been transfered

//Old TPL Dataflow CTP

sourceBlock.LinkTo(targetBlock, linkFilter, false);

//New TPL Dataflow CTP

DataflowLinkOptions dataflowLinkOptions = new DataflowLinkOptions() { MaxMessages = 1 };

sourceBlock.LinkTo(targetBlock, dataflowLinkOptions);

//Close the link after the a message had been transfered

//Old TPL Dataflow CTP

sourceBlock.LinkTo(targetBlock, linkFilter, true);

//New TPL Dataflow CTP

DataflowLinkOptions dataflowLinkOptions = new DataflowLinkOptions() { MaxMessages = 1 };

sourceBlock.LinkTo(targetBlock, dataflowLinkOptions);

//Close the link after the a spefici number of message had been transfered

//Old TPL Dataflow CTP

// Can't be done.

//New TPL Dataflow CTP

DataflowLinkOptions dataflowLinkOptions = new DataflowLinkOptions() { MaxMessages = 100 }; // 100 is a dummy numebr any positive integer will be fine

sourceBlock.LinkTo(targetBlock, dataflowLinkOptions);

הוסף תגובה
facebook linkedin twitter email

כתיבת תגובה

האימייל לא יוצג באתר. שדות החובה מסומנים *

תגובה אחת

  1. Wilbanks16 ביוני 2012 ב 17:10

    Hi there to all, it's truly a fastidious for me to pay a quick visit this web page, it contains useful Information.

    הגב