Code inspection: Avoid using 'async' for methods and functions with the 'void' return type but without a parameter of type 'System.EventArgs'
This inspection detects methods and functions where the async modifier is used together with the void return type, but the method does not accept a parameter of type System.EventArgs. Such methods are discouraged because unhandled exceptions in these methods cannot be awaited and may crash the application.
The quick fix wraps the body of the async void method in a try-catch block. This ensures that any exceptions thrown within the method are caught, preventing unhandled exceptions that could crash the application. You can replace the throw; statement with custom error handling logic depending on the specific requirements of your application.
While this quick fix makes the async void method safer by catching exceptions, it’s generally a better practice to use Task as the return type for async methods wherever possible, except in specific scenarios like event handlers where void is required.