C 2.0 practical guide for programmers PHẦN 9

O'Reilly mang lại sáng tạo đa dạng với nhau để nuôi dưỡng những ý tưởng tia lửa các ngành công nghiệp cách mạng. Chúng tôi chuyên trong tài liệu công cụ mới nhất và các hệ thống, dịch kiến thức của sáng tạo vào các kỹ năng hữu ích cho những người trong các chiến hào. | Threads 197 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 public class MyThread public MyThread int number t new Thread Run number private void Run while true number 1000 0 number public void Suspend nThread 0 suspended number public void Resume nThread 0 resumed number public void Stop nThread 0 stopped number private Thread t private int number public class MainThread public static void Main Main Started. MyThread t1 new MyThread 1 MyThread t2 new MyThread 2 10 1000 10 1000 10 1000 10 1000 Main done. 198 Chapter 9 Resource Disposal Input Output and Threads 48 49 50 Output Main Started. 1211211211211 Thread 1 suspended 22222 Thread 1 resumed 121121121121121 Thread 1 stopped 22222 Thread 2 stopped Main done. It is worth noting that when a thread is aborted the runtime system throws a ThreadAbortException that cannot be caught. However it does execute all finally blocks before the thread terminates. Also an exception is thrown if a Suspend invocation is made on a thread that is already suspended or if a Resume invocation is made on a thread that is not suspended. Because code that uses the Suspend and Resume methods is deadlock-prone both methods have been deprecated made obsolete in the latest version of the .NET Framework. Joining and Determining Alive Threads A thread is alive once it is moved from the Unstarted state and has yet to be aborted or terminated normally. If a thread is alive then the method IsAlive returns true. Otherwise it returns false. A thread may also block itself until another thread has terminated. Hence the thread that invokes the method specifiedThread .Join .

Không thể tạo bản xem trước, hãy bấm tải xuống
TÀI LIỆU MỚI ĐĂNG
2    156    1    09-05-2024
Đã 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.