tailieunhanh - Network Programming in .NET With C# and Visual Basic .NET phần 6

Các khóa (hoặc syncLock) là cần thiết cho sự ổn định ứng dụng. Nếu hai chủ đề liên tục truy cập vào yếu tố người sử dụng giao diện tương tự tại cùng một thời gian, giao diện người dùng của ứng dụng sẽ trở thành không phản hồi. Cuối cùng, không gian tên luồng là: C # | Avoiding deadlocks 261 ----------------- Figure Thread pool sample application. The lock or syncLock is required for application stability. If two threads repeatedly access the same user interface element at the same time the application s UI becomes unresponsive. Finally the threading namespace is required C using imports To test the application run it from Visual Studio .NET and wait for a minute or two for the increments-per-second value to settle on a number Figure . You can experiment with this application and see how performance increases and decreases under certain conditions such as running several applications or running with low memory. Avoiding deadlocks Deadlocks are the computing equivalent of a Catch-22 situation. Imagine an application that retrieves data from a Web site and stores it in a database. Users can use this application to query from either the database or the Web site. These three tasks would be implemented as separate threads and for whatever reason no two threads can access the Web site or the database at the same time. The first thread would be Wait for access to the Web site. Restrict other threads access to the Web site. Wait for access to the database. I Chapter 10 262 Load balancing Restrict other threads access to the database. Draw down the data and write it to the database. Relinquish the restriction on the database and Web site. The second thread would be Wait for access to the database. Restrict other threads access to the database. Read from the database. Execute thread three and wait for its completion. Relinquish the restriction on the database. The third thread would be Wait for access to the Web site. Restrict other threads access to the Web site. Read from the Web site. Relinquish the restriction on the Web site. Any thread running on its own will complete without any errors however

TỪ KHÓA LIÊN QUAN
crossorigin="anonymous">
Đã 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.