How do I have an object notify me of any changes in real time?

Events provide a generally useful way for objects to signal state changes that may be useful to clients of that object. In order to support this, you need to create an event of type EventHandler with the name <property name>Changed. Then, in the property setter of the object, after you store the value (or do whatever you have to do to ensure that getting the value will return the new value), fire the event.

The event model in the .NET Framework is based on having an event delegate that connects an event with its handler. To raise an event, two elements are needed:

  • A class that holds the event data.
  • This class must derive from the base class EventArgs.
A delegate that points to a method that provides the response to the event.

Example:
public delegate void EventHandler(Object sender, EventArgs e);
public event EventHandler DataChangedEventHandler;


Index

 
Printer friendly version of the FAQ-CSHARP--Real-Time-Object-Notification page


Sponsored links

.Net Application Updating
One easy to use component adds safe and reliable updating features. Download today for a free trial.
Build IT Knowledge with Current & Trusted Content
Helps Employees Develop & Hone New Technical Programming Skills. Sign Up & Get Full Access.
Check Out IT Certification Preparation Materials
Sign Up With SkillSoft & Get Access to Training Materials for Over 50 Professional Certifications.
Villanova University Six Sigma & IT Certificate Programs
100% Online programs in Six Sigma, IS Security, CISSP Prep, Business Analysis, Proj. Mgmt. and more!
.Net Localization in three simple steps (WYSIWYG)
Localize .Net, C#/C/C++ & Delphi apps visually. HTML, HTML Help, XML & databases. Try Sisulizer now!

Advertisement



Free Magazine

Free Magazines
eWeek The essential technology information source for builders of e-business.... subscribe now

Newsletter | Submit Content | About | Advertising | Awards | Contact Us | Link to us |
© 1996-2008 Community Networks Ltd All rights reserved. Reproduction in whole or in part, in any form or medium without express written permission is prohibited. Violators of this policy may be subject to legal action. Please read Terms Of Use and Privacy Statement for more information. Development by Synchron Data - .NET development.