Provide another example of VSTHRD100 resolution

This commit is contained in:
Andrew Arnott 2022-06-14 13:42:00 -06:00 коммит произвёл GitHub
Родитель 73aa23b392
Коммит 0847b84735
Не найден ключ, соответствующий данной подписи
Идентификатор ключа GPG: 4AEE18F83AFDEB23
1 изменённых файлов: 17 добавлений и 1 удалений

Просмотреть файл

@ -24,7 +24,9 @@ async Task DoSomethingAsync()
}
```
A code fix is offered that automatically changes the return type of the method.
A code fix is offered that automatically changes the return type of the method.
### Event handlers
For event handlers, avoid `async void` by using `RunAsync`:
```csharp
@ -37,4 +39,18 @@ private async Task OnEventAsync(object sender, EventArgs e)
}
```
When using method group syntax as an argument, you can define the method with the required signature, without the `async` modifier, and define an anonymous delegate or lambda within the method, like this:
```cs
var menuItem = new MenuCommand(HandleEvent, commandId);
private void HandleEvent(object sender, EventArgs e)
{
_ = joinableTaskFactory.RunAsync(async () =>
{
// async code
});
}
```
Refer to [Async/Await - Best Practices in Asynchronous Programming](https://msdn.microsoft.com/en-us/magazine/jj991977.aspx) for more info.