This question already has an answer here:
Simple question: Are there any guidelines, either published by Microsoft itself or a common practice regarding to declaring tasks on type and interface contracts?
So far, I've seen many different approaches:
Synchronous and asynchronous using TAP (most .NET types):
void DoSomething();
Task DoSomethingAsync();
TAP only:
Task DoSomething(); // notice, no 'Async' member naming
Split contracts:
interface IDoSomething {
}
interface IDoSomethingSync : IDoSomething {
void DoSomething();
}
interface IDoSomethingAsync: IDoSomething {
Task DoSomething();
}
...or finally, just making a contract without any tasks and leave it up to the consumer.
Is there an official way to declare this? For a while, I sticked to the first example since it's the most common one in the .NET framework, but even there it's sometimes not consistent because of legacy reasons.
Aucun commentaire:
Enregistrer un commentaire