CÁC GIẢI PHÁP LẬP TRÌNH C# - Trang 141

141

Chương 4: Tiểu trình, tiến trình, và sự đồng bộ

} catch (ThreadStateException) {

Console.WriteLine("{0} : Thread wasn't " +

"suspended.",

DateTime.Now.ToString("HH:mm:ss.ffff"));

}

break;

case 'I':

// Gián đoạn tiểu trình thứ hai.

Console.WriteLine("{0} : Interrupting second " +

"thread.",

DateTime.Now.ToString("HH:mm:ss.ffff"));

thread.Interrupt();

break;

case 'E':

// Hủy bỏ tiểu trình thứ hai và truyền một đối tượng

// trạng thái cho tiểu trình đang bị hủy,

// trong trường hợp này là một thông báo.

Console.WriteLine("{0} : Aborting second thread.",

DateTime.Now.ToString("HH:mm:ss.ffff"));

thread.Abort("Terminating example.");

// Đợi tiểu trình thứ hai kết thúc.

thread.Join();

break;

}

} while (command != 'E');

// Nhấn Enter để kết thúc.

Console.WriteLine("Main method complete. Press Enter.");

Console.ReadLine();

}

}