Click here to Skip to main content
Licence 
First Posted 11 Aug 2002
Views 37,091
Bookmarked 13 times

Making and using events.

By | 11 Aug 2002 | Article
Make a class that exports its custom event.
Making and using events. Make your own events and use them.

Introduction

In this example I made three classes:

1 - class InfoSupplier Exposes its own event which carries some information. For example a Information agency which receives information from its agents and then exposes this information to the TV, news and so on.

// This is the delegate ( in fact it defines signature of the function )
public	delegate void InfoEventHandler(object source, InfoEventArgs args);

// This is an event, it is a data member of the type of the delegate.
public	event	InfoEventHandler	OnInfoArrivedHandler;

2 - class InfoListener Uses the events which are raised from the InfoSupplier instances. When receives a new event it displays the information which the event has brought. This class has one more special method : void PublishInfo(object source, InfoEventArgs info); which must have the same signature as the delegate declared in the class InfoSupplier.

3 - class InfoEventArgs : EventArgs This is the actual event which is raised and received. It contains one data member, which describes an event. U can put here as much data members as u want, in order to fully describe your event.

This is the idea of using events and it’s the same in Timer events and so on…easy.

License

This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here

About the Author

rosen

Web Developer

Bulgaria Bulgaria

Member



Sign Up to vote   Poor Excellent
Add a reason or comment to your vote: x
Votes of 3 or less require a comment

Comments and Discussions

 
You must Sign In to use this message board. (secure sign-in)
 
Search this forum  
 FAQ
    Noise  Layout  Per page   
  Refresh
GeneralSuggestions PineditorJames T. Johnson8:57 12 Aug '02  

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

Permalink | Advertise | Privacy | Mobile
Web04 | 2.5.120517.1 | Last Updated 12 Aug 2002
Article Copyright 2002 by rosen
Everything else Copyright © CodeProject, 1999-2012
Terms of Use
Layout: fixed | fluid