Provide another example of VSTHRD100 resolution
This commit is contained in:
Родитель
73aa23b392
Коммит
0847b84735
|
@ -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.
|
||||
|
|
Загрузка…
Ссылка в новой задаче