[Reading Notes] event

Source: Internet
Author: User
 an event is a method that allows sending signals to indicate the occurrence of an important event. 
Using system; using system. collections. generic; using system. LINQ; using system. text; namespace event {class program {static void main (string [] ARGs) {longtask it = new longtask (); it. onpolicyprogress + = new longtask. notifyprogressdelegate (it_onnotifyprogress); it. performtask (); console. readline ();} static void it_onpolicyprogress (progressargs Pa) {console. writeline ("Progress on long task complete. {0} % complete. ", Pa. percentcomplete) ;}} class longtask {Public Delegate void policyprogressdelegate (progressargs Pa); // declare a delegate public event policyprogressdelegate onpolicyprogress; // create an event public void limit mtask () {for (INT I = 0; I <10000; I ++) {// perform some processing //... // configure y subscribers that progress was made if (I % 100 = 0) {onnotifyprogress (New progressargs (INT) I/100 ));}}}} class progressargs {public int percentcomplete; Public progressargs (INT pctcomplete) {percentcomplete = pctcomplete ;}}}
Event Overview

Events have the following features:

    • The publisher determines when an event is triggered, and the user determines the operation to be performed to respond to the event.

    • An event can have multiple subscribers. One subscriber can process multiple events from multiple publishers.

    • Events without subscribers will never be called.

    • Events are usually usedNotificationUser operations (for example, click a button in the graphic user interface or select an operation from the menu ).

    • If an event has multiple subscribers, when this event is triggered, multiple events are synchronously called for processing.Program. To call events asynchronously, see call synchronous methods in asynchronous mode.

    • You can use the event synchronization thread.

    • In the. NET Framework class library, events are based on the eventhandler delegate and eventargs base class.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.