1. Trang chủ
  2. » Công Nghệ Thông Tin

Subscribing to an Event

1 265 0
Tài liệu đã được kiểm tra trùng lặp

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

THÔNG TIN TÀI LIỆU

Thông tin cơ bản

Tiêu đề Subscribing to an event
Định dạng
Số trang 1
Dung lượng 6,62 KB

Các công cụ chuyển đổi và chỉnh sửa cho tài liệu này

Nội dung

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 controlli

Trang 1

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

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

TỪ KHÓA LIÊN QUAN

w