It??™s worth noting that when we use the step to find the next
value we don??™t need to change anything within the instance??”both of these types are
immutable and so can be freely shared between threads, returned as properties, and
used for all kinds of other operations without fear.
With the DateTimeRange type in place, I could replace the DateRange property in
my timetable application, and remove the StartDate and EndDate properties entirely.
The closely related values are now nicely encapsulated, the birds are singing, and all is
right with the world. There??™s a lot more we could do to our Range type, but for the
moment it??™s served its purpose well.
The Range type is just one example of a way in which iteration presents itself as a
natural option in C# 2 where it would have been significantly less elegant in C# 1. I
hope you??™ll consider it next time you find yourself writing a start/end pair of variables
or properties. As examples go, however, it??™s pretty tame??”iterating over a range isn??™t
exactly a novel idea. To close the chapter, we??™ll look at a considerably less conventional
use of iterator blocks??”this time for the purpose of providing one side of a multithreaded
conversation.
6.4 Pseudo-synchronous code with
the Concurrency and Coordination Runtime
The Concurrency and Coordination Runtime (CCR) is a library developed by Microsoft to
offer an alternative way of writing asynchronous code that is amenable to complex
coordination.
Pages:
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355