Examples of combinators include WhenAll and WhenAny, and are discussed in the Using the Built-in Task-based Combinators section of the article Consuming the Task-based Asynchronous Pattern.įor examples of how the TAP syntax differs from the syntax used in legacy asynchronous programming patterns such as the Asynchronous Programming Model (APM) and the Event-based Asynchronous Pattern (EAP), see Asynchronous Programming Patterns. Methods that are devoted exclusively to the creation, manipulation, or combination of tasks (where the asynchronous intent of the method is clear in the method name or in the name of the type to which the method belongs) need not follow this naming pattern such methods are often referred to as combinators. Also, consider adding a CancellationToken parameter even if the TAP method's synchronous counterpart does not offer one. Any data that would have been returned through an out or ref parameter should instead be returned as part of the TResult returned by Task, and should use a tuple or a custom data structure to accommodate multiple values. However, out and ref parameters are exempt from this rule and should be avoided entirely. The parameters of a TAP method should match the parameters of its synchronous counterpart and should be provided in the same order. If a method starts an asynchronous operation but does not return an awaitable type, its name should start with Begin, Start, or some other verb to suggest that this method does not return or throw the result of the operation.Ī TAP method returns either a or a, based on whether the corresponding synchronous method returns void or a type TResult. For example, if the class already has a GetAsync method, use the name GetTaskAsync. If you're adding a TAP method to a class that already contains an EAP method name with the Async suffix, use the suffix TaskAsync instead. For example, an asynchronous Get operation that returns a Task can be named GetAsync. Asynchronous methods in TAP include the Async suffix after the operation name for methods that return awaitable types, such as Task, Task, ValueTask, and ValueTask. EAP requires a method that has the Async suffix and also requires one or more events, event handler delegate types, and EventArg-derived types. This contrasts with both the Asynchronous Programming Model (APM or IAsyncResult) pattern and the Event-based Asynchronous Pattern (EAP). TAP uses a single method to represent the initiation and completion of an asynchronous operation. It is based on the Task and Task types in the namespace, which are used to represent asynchronous operations. NET, The task-based asynchronous pattern is the recommended asynchronous design pattern for new development.
0 Comments
Leave a Reply. |
Details
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |