Subscribing to an Event

1 264 0
Subscribing to an Event

Đang tải... (xem toàn văn)

Thông tin tài liệu

Subscribing to an Event Like delegates, events come ready-made with a += operator. You subscribe to an event by using this += operator. In the automated factory, the software controlling each machine can arrange for the shutdown methods to be called when the MachineOverheating event is raised like this: TemperatureMonitor tempMonitor = new TemperatureMonitor(); . tempMonitor.MachineOverheating += delegate { folder.StopFolding(0) }; tempMonitor.MachineOverheating += welder.FinishWelding; tempMonitor.MachineOverheating += painter.PaintOff; Notice that the syntax is the same as for adding a method to a delegate. You can even subscribe by using an anonymous method. When the tempMonitor.MachineOverheating event runs, it will call all the subscribing methods and shut the machines down. . Subscribing to an Event Like delegates, events come ready-made with a += operator. You subscribe to an event by using this += operator. In the automated. TemperatureMonitor tempMonitor = new TemperatureMonitor(); . tempMonitor.MachineOverheating += delegate { folder.StopFolding(0) }; tempMonitor.MachineOverheating

Ngày đăng: 28/10/2013, 20:15

Từ khóa liên quan

Tài liệu cùng người dùng

Tài liệu liên quan