Exemple #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("Aborting thread...");
            Console.WriteLine("Abort() 호출 : {0} ", stopwatch.Elapsed.TotalMilliseconds);
            t1.Abort();
            printThreadState(t1.ThreadState);

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

            Console.WriteLine("Finished");
            Console.WriteLine("끝남: {0} ", stopwatch.Elapsed.TotalMilliseconds);
        }
Exemple #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("Abouting thread...");
            t1.Abort();

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

            Console.WriteLine("Finished");
        }