Comment et quand utiliser 'async' et 'await'
Comment et quand utiliser 'async' et 'await'
Comment et quand utiliser 'async' et 'await'
Re: Comment et quand utiliser 'async' et 'await'
Lors de l'utilisation de `async` et `await`, le compilateur génère une machine à états en arrière-plan.
Voici un exemple sur lequel j'espère pouvoir expliquer quelques détails de haut niveau sur ce qui se passe :
```
public async Task MyMethodAsync()
{
Task longRunningTask = LongRunningOperationAsync();
// independent work which doesn't need the result of LongRunningOperationAsync can be done here
//and now we call await on the task
int result = await longRunningTask;
//use the result
Console.WriteLine(result);
}
public async Task LongRunningOperationAsync() // assume we return a
Voici un exemple sur lequel j'espère pouvoir expliquer quelques détails de haut niveau sur ce qui se passe :
```
public async Task MyMethodAsync()
{
Task longRunningTask = LongRunningOperationAsync();
// independent work which doesn't need the result of LongRunningOperationAsync can be done here
//and now we call await on the task
int result = await longRunningTask;
//use the result
Console.WriteLine(result);
}
public async Task LongRunningOperationAsync() // assume we return a