.NET ActionBlock <T> , . .
:
ActionBlock<string> _hmiAgent=new ActionBlock<string>(async msg=>{
TcpIpMessageSenderClient.ConnectAndSendMessage(msg.PadRight(80, ' '));
await Task.Delay(2000);
);
foreach ( ....)
{
_hmiAgent.Post(someMessage);
}
_hmiAgent.Complete();
await _hmiAgent.Completion;
ActionBlock - , , , . . , , , .
, , TransformBlock < , Tout > . , , , :
TransformBlock<string> _hmiAgent=new TransformBlock<string,string>(
msg=>msg.PadRight(80, ' '));
ActionBlock<string> _tcpBlock=new ActionBlock<string>(async msg=>{
TcpIpMessageSenderClient.ConnectAndSendMessage());
await Task.Delay(2000);
);
var linkOptions=new DataflowLinkOptions{PropagateCompletion = true};
_hmiAgent.LinkTo(_tcpBlock);
_hmiAgent.Post(someMessage);
, _tcpBlock:
_hmiAgent.Complete();
await _tcpBlock.Completion;
Visual Studio 2015+ TPL
Bar Arnon TPL Dataflow - , , , .