static void Main(string[] args) { SideTask task = new SideTask(1000); Thread th = new Thread(new ThreadStart(task.KeepAlive)); th.IsBackground = false; Console.WriteLine("Starting thread..."); th.Start(); Thread.Sleep(100); //Console.WriteLine("Interrupting thread..."); //th.Interrupt(); //Abort보단 인터럽트를 쓰는것이 낫다 th.Suspend(); //멈췄다가 다시 실행 시키고 싶을때 사용 Console.WriteLine("Wating"); Thread.Sleep(3000); th.Resume(); //Console.WriteLine("Waiting until thread stop"); //th.Join(); Console.WriteLine("Done!!"); }
static void Main(string[] args) { SideTask task = new SideTask(500); Thread th = new Thread(new ThreadStart(task.KeepAlive)); th.IsBackground = false; Console.WriteLine("Starting thread..."); th.Start(); Thread.Sleep(100); //Console.WriteLine("Intterrupting thread..."); //th.Interrupt(); th.Suspend(); Console.WriteLine("Waiting"); Thread.Sleep(3000); th.Resume(); Console.WriteLine("Waiting until thread stops..."); th.Join(); Console.WriteLine("Finished"); }
static void Main(string[] args) { SideTask task = new SideTask(500); Thread th = new Thread(new ThreadStart(task.KeepAlive)); th.IsBackground = false; WriteLine(); th.Start(); Thread.Sleep(100); //th.Interrupt(); th.Suspend(); Thread.Sleep(3000); th.Resume(); th.Join(); }