Beispiel #1
0
        static void Main(string[] args)
        {
            Stopwatch stopwatch = Stopwatch.StartNew();
            SideTask  task      = new SideTask(100);
            Thread    t1        = new Thread(new ThreadStart(task.KeepAlive));

            t1.IsBackground = false;

            Console.WriteLine("Start() 호출 : {0}", stopwatch.Elapsed.TotalMilliseconds);
            Console.WriteLine("Starting Thread...");
            t1.Start();
            printThreadState(t1.ThreadState);

            Console.WriteLine("sleep() 호출 : {0}", stopwatch.Elapsed.TotalMilliseconds);
            Thread.Sleep(100);
            printThreadState(t1.ThreadState);

            Console.WriteLine("Interrupting thread...");
            Console.WriteLine("Interrupt() 호출 : {0} ", stopwatch.Elapsed.TotalMilliseconds);
            t1.Interrupt();
            printThreadState(t1.ThreadState);

            Console.WriteLine("Waiting until thresd stops...");
            t1.Join();
            printThreadState(t1.ThreadState);

            Console.WriteLine("Finished");
            Console.WriteLine("끝남: {0} ", stopwatch.Elapsed.TotalMilliseconds);
        }
Beispiel #2
0
        static void Main(string[] args)
        {
            SideTask task = new SideTask(100);
            Thread   t1   = new Thread(new ThreadStart(task.KeepAlive));

            t1.IsBackground = false;

            Console.WriteLine("Starting thread...");
            t1.Start();

            Thread.Sleep(100);

            Console.WriteLine("Interrupting thread...");
            t1.Interrupt();

            Console.WriteLine("Wating until thread stops...");
            t1.Join();

            Console.WriteLine("Finished");
        }
Beispiel #3
0
        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("Interrupting thread...");
            //th.Interrupt();
            th.Suspend();

            Console.WriteLine("waiting");
            Thread.Sleep(3000);
            th.Resume();

            Console.WriteLine("waiting until thread stops...");
            th.Join();
            Console.WriteLine("Done");
        }