Skip to content
This repository has been archived by the owner on Nov 8, 2018. It is now read-only.

Add special rule for async void eventhandlers. #53

Open
JohanLarsson opened this issue Sep 29, 2016 · 1 comment
Open

Add special rule for async void eventhandlers. #53

JohanLarsson opened this issue Sep 29, 2016 · 1 comment

Comments

@JohanLarsson
Copy link

JohanLarsson commented Sep 29, 2016

private async void OnChanged(object sender, EventArgs e)
{
    ...
}

What about adding a rule AvoidAsyncVoidInEventhandlers?
The reason for this would be to be able to tune severity separately for them.
Heuristics could be: method with two arguments of type object and assignable to EventArgs or maybe it can be figured out from climbing around the syntax tree that the method is only used for subscribing to an event.

Perhaps there could be another analyzer checking that there is try-catch surrounding all awaits.

@AArnott
Copy link

AArnott commented May 2, 2018

Given that async void methods crash the process if they throw, I don't think they should ever be used, event handlers or not.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants