Skip to Content
C#并发编程经典实例(第2版)
book

C#并发编程经典实例(第2版)

by Stephen Cleary
November 2020
Intermediate to advanced
226 pages
5h 34m
Chinese
Posts & Telecom Press
Content preview from C#并发编程经典实例(第2版)
60
5
if
(item == 1)
throw new
InvalidOperationException(
"
Blech.");
return
item * 2;
});
var
subtractBlock =
new
TransformBlock<
int
,
int
>(item => item - 2);
multiplyBlock.LinkTo(subtractBlock,
new
DataflowLinkOptions { PropagateCompletion =
true
});
multiplyBlock.Post(1);
await
subtractBlock.Completion;
}
catch
(AggregateException)
{
// 捕获异常
}
每个块都会将收到的错误包装在
AggregateException
中,即便错误本身已经是
Aggregate-
Exception
,也会如此。在管道中,如果前期就出现错误,并且该错误在被观察到之前已经
沿着若干个链接传递,那么原始错误会被包装在多层
AggregateException
中。在这种情况
下,
AggregateException.Flatten
方法可以简化错误处理。
讨论
在创建网格或管道时,考虑如何处理错误。在较为简单的情况下,最好传播错误并在最后
一次性将它们全部捕获。在更为复杂的网格中,则可能需要在数据流完成时观察每个块。
如果在异常出现时,仍旧希望数据流块继续工作,那么可以把异常当作另一种数据来处 ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.

Read now

Unlock full access

More than 5,000 organizations count on O’Reilly

AirBnbBlueOriginElectronic ArtsHomeDepotNasdaqRakutenTata Consultancy Services

QuotationMarkO’Reilly covers everything we've got, with content to help us build a world-class technology community, upgrade the capabilities and competencies of our teams, and improve overall team performance as well as their engagement.
Julian F.
Head of Cybersecurity
QuotationMarkI wanted to learn C and C++, but it didn't click for me until I picked up an O'Reilly book. When I went on the O’Reilly platform, I was astonished to find all the books there, plus live events and sandboxes so you could play around with the technology.
Addison B.
Field Engineer
QuotationMarkI’ve been on the O’Reilly platform for more than eight years. I use a couple of learning platforms, but I'm on O'Reilly more than anybody else. When you're there, you start learning. I'm never disappointed.
Amir M.
Data Platform Tech Lead
QuotationMarkI'm always learning. So when I got on to O'Reilly, I was like a kid in a candy store. There are playlists. There are answers. There's on-demand training. It's worth its weight in gold, in terms of what it allows me to do.
Mark W.
Embedded Software Engineer

You might also like

解密金融数据

解密金融数据

Justin Pauley
PHP编程:第4版

PHP编程:第4版

Kevin Tatroe, Peter MacIntyre

Publisher Resources

ISBN: 9787115550606