TAILIEUCHUNG - Declaring an Event

Tuyên bố một sự kiện Bạn tuyên bố một sự kiện trong một lớp học dự định để hoạt động như một nguồn sự kiện. Một nguồn sự kiện thường là một lớp học mà giám sát môi trường của nó, và đặt ra một sự kiện quan trọng xảy ra khi một cái gì đó. Trong các nhà máy tự động | Declaring an Event You declare an event in a class intended to act as an event source. An event source is usually a class that monitors its environment and raises an event when something significant happens. In the automated factory an event source could be a class that monitors the temperature of each machine. The temperature monitor class would raise a machine overheating event if it detects that a machine has exceeded its thermal radiation boundary . it has become too hot . An event maintains a list of methods to call when it is raised. These methods are sometimes referred to as subscribers. These methods should be prepared to handle the machine overheating event and take the necessary corrective action shut the machines down. You declare an event in a way similar to declaring a field. However because events are intended be used with delegates the type of an event must be a delegate and you must prefix the declaration with the event keyword. For example here s the StopMachineryDelegate delegate from the automated factory. I have relocated it to a new class called TemperatureMonitor which provides an interface to the various electonic probes monitoring the temperature of the equipment this is a more logical place for the event than the Controller class class TemperatureMonitor public delegate void StopMachineryDelegate . You can define the MachineOverheating event which will invoke the stopMachineryDelegate like this class TemperatureMonitor public delegate void StopMachineryDelegate public event StopMachineryDelegate MachineOverheating . The logic not shown in the TemperatureMonitor class automatically raises the MachineOverheating event as necessary. An event maintains its own internal collection of attached delegates so there is no need to manually maintain your delegate .

TAILIEUCHUNG - Chia sẻ tài liệu không giới hạn
Địa chỉ : 444 Hoang Hoa Tham, Hanoi, Viet Nam
Website : tailieuchung.com
Email : tailieuchung20@gmail.com
Tailieuchung.com là thư viện tài liệu trực tuyến, nơi chia sẽ trao đổi hàng triệu tài liệu như luận văn đồ án, sách, giáo trình, đề thi.
Chúng tôi không chịu trách nhiệm liên quan đến các vấn đề bản quyền nội dung tài liệu được thành viên tự nguyện đăng tải lên, nếu phát hiện thấy tài liệu xấu hoặc tài liệu có bản quyền xin hãy email cho chúng tôi.
Đã phát hiện trình chặn quảng cáo AdBlock
Trang web này phụ thuộc vào doanh thu từ số lần hiển thị quảng cáo để tồn tại. Vui lòng tắt trình chặn quảng cáo của bạn hoặc tạm dừng tính năng chặn quảng cáo cho trang web này.