Method Naming and Overloading

Part of all the asynchronous patterns is convention. This is no different for the TAP. The first guideline is to give the method an Async suffix in its name. In case there’s already such a method for the EAP, the alternative TaskAsync suffix is picked. A good example of this is the WebClient class, which we explored in the previous section. For types that were based on the APM, no such conflict exists. A good example is on the FileStream class, which has the following members for Read and Write operations in .NET 4.5:

// Sychronous methodsabstract int Read(byte[] buffer, int offset, int count);abstract void Write(byte[] buffer, int offset, int count);// APM methodsvirtual IAsyncResult ...

Get C# 5.0 Unleashed now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.