TAILIEUCHUNG - Apress-Visual CSharp 2010 Recipes A Problem Solution Approach_1

Trong trường hợp này, một thông điệp để hiển thị. chuỗi nhà nước = "Hẹn giờ hết các khoảng thời gian hẹn giờ mới từ giao diện điều khiển cho đến khi người sử dụng / / nhập vào 0 (zero). Các giá trị không hợp lệ sử dụng một giá trị mặc định | CHAPTER 4 THREADS PROCESSES AND SYNCHRONIZATION using System using namespace class Recipe04_03 public static void Main . Create the state object that is passed to the TimerHandler method when it is triggered. In this case a message to display. string state Timer expired. 0 Creating Timer. HH mm Create a timer that fires first after 2 seconds and then every second. Use an anonymous method for the timer expiry handler. using Timer timer new Timer delegate object s 0 1 HH mm s . . state 2000 1000 . . int period Read the new timer interval from the console until the user enters 0 zero . Invalid values use a default value of 0 which will stop the example. do try . . period . catch FormatException period 0 Change the timer to fire using the new interval starting immediately. if period 0 0 period while period 0 165 CHAPTER 4 THREADS PROCESSES AND SYNCHRONIZATION Wait to continue. Main method complete. Press Enter. 4-4. Execute a Method at a Specific Time Problem You need to execute a method in a separate thread at a specific time. Solution Declare a method containing the code you want to execute. The method s signature must match that defined by the delegate that is it must return void and take a single object argument. Create a object and pass it the method you want to execute along with a state object that the timer will pass to your method when the timer expires. Calculate the time difference between the current time and the desired execution time and configure the Timer object to fire once after this period of time. How It Works Executing a method at a particular time is often useful. For example you might need to back up data at 1 . daily. Although primarily used for calling methods at .

TỪ KHÓA LIÊN QUAN
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.