Đang chuẩn bị liên kết để tải về tài liệu:
C 2.0 practical guide for programmers PHẦN 9

Không đóng trình duyệt đến khi xuất hiện nút TẢI XUỐNG

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. | 9.3 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 this.number number t.Start private void Run while true Thread.Sleep number 1000 System.Console.Write 0 number public void Suspend System.Console.WriteLine nThread 0 suspended number t.Suspend public void Resume System.Console.WriteLine nThread 0 resumed number t.Resume public void Stop System.Console.WriteLine nThread 0 stopped number t.Abort private Thread t private int number public class MainThread public static void Main System.Console.WriteLine Main Started. MyThread t1 new MyThread 1 MyThread t2 new MyThread 2 Thread.Sleep 10 1000 t1.Suspend Thread.Sleep 10 1000 t1.Resume Thread.Sleep 10 1000 t1.Stop Thread.Sleep 10 1000 t2.Stop System.Console.WriteLine 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. 9.3.5 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 .

Đã 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.