22 May 2019

c#basics event EventHandler OnEvent

delev

We learned about the event keyword and the EventHandler class. we learned the delegate which is defined for the event “behind the scenes” (object sender, EventArgs e). we learned about the EventArgs and saw how to create our own customized EventArgs (inherit from EventArgs).  we saw the naming convention of the event-name ,which should state the scenario in the correct time tense (i.e. VideoEncod-ed, VideoEncod-ing, etc.) . we saw that the Event is fired from a method call On<Event-Name> (in the publisher side); in the subscriber side- we saw that we have to define a method called <Event-name>EventHandler and to register it to the event. we saw that events are different from delegate, for example you cannot override the event using the “=”  operation, but instead- you must use the “+=” operation to add your method. then we saw how WinForm OnClick is registering the event and later on executing it. finally we saw how to register our method into the .NET Timer class and execute it in each interval

More topics covered:

  • delegate Combine
  • using new keyword on delegate
  • delegate BeginInvoke EndInvoke
  • Generic EventHandler<T>
  • Who is the objectsender
  • using this for the object sender

Links:

Leave a comment

Design a site like this with WordPress.com
Get started