Geeks With Blogs
Deeksha Sharma

To respond to an event, you define an event handler method in the event receiver. This method must match the signature of the delegate for the event you are handling. In the event handler, you perform the actions that are required when the event is raised, such as collecting user input after the user clicks a button. To receive notifications when the event occurs, your event handler method must subscribe to the event.

The following example shows an event handler method named c_ThresholdReached that matches the signature for the EventHandler delegate. The method subscribes to theThresholdReached event.

class Program
{
    static void Main(string[] args)
    {
        Counter c = new Counter();
        c.ThresholdReached += c_ThresholdReached;

        // provide remaining implementation for the class
    }

    static void c_ThresholdReached(object sender, EventArgs e)
    {
        Console.WriteLine("The threshold was reached.");
    }
}
Posted on Friday, December 12, 2014 6:34 AM | Back to top


Comments on this post: Event Handlers

No comments posted yet.
Your comment:
 (will show your gravatar)


Copyright © Deeksha Sharma | Powered by: GeeksWithBlogs.net