Click here to Skip to main content
15,890,717 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hello Everybody,

I am very new to VB.NET, so please bear with me on this.

I wrote my first VB.NET application and have a class that raises an event:

Public Event CalibrationsComplete(ByVal bHardwareNeedsCalibration As Boolean)

I ran code analysis and got the following warning:

MSBUILD : warning CA1009: Microsoft.Design : Declare the first parameter of 'clsCalibrations.CalibrationsCompleteEventHandler' as an object named 'sender'.

MSBUILD : warning CA1009: Microsoft.Design : Declare the second parameter of 'clsCalibrations.CalibrationsCompleteEventHandler' as an EventArgs, or an instance of a type that extends EventArgs, named 'e'.

How can a resolve this warning?

Can I just ignore it?

Thank you

Gary

What I have tried:

Could not think of what to try, please help
Posted
Updated 23-Jul-21 11:43am

1 solution

Read the messages: they explicitly tell you what to do in order to fix the problem and make the warnings disapear:
Quote:
MSBUILD : warning CA1009: Microsoft.Design : Declare the first parameter of 'clsCalibrations.CalibrationsCompleteEventHandler' as an object named 'sender'.

MSBUILD : warning CA1009: Microsoft.Design : Declare the second parameter of 'clsCalibrations.CalibrationsCompleteEventHandler' as an EventArgs, or an instance of a type that extends EventArgs, named 'e'.


All event handlers should follow the same pattern: two parameters.
The first is an Object and is called sender - this is the class instance that raised the event. For a Form, it's the specific form instance that the user interacted with to generate the event by clicking a button for example.
The second is called e and is an EventArgs (or a class derived from EventArgs) instance. If you need to add information to the Event directly, you create a class derived from EventArgs that adds the required data and use that class instead

If you don't follow these rules, you - rightly - get a warning. While it is possible to ignore it, like all other warnings you (particularly as a beginner) should treat them as errors. In fact, my default project template sets "treat errors as warnings" to "on" so that my apps will not compile with any warnings. It saves a lot of time later on!
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900