Ejemplo n.º 1
0
        public static void Start()
        {
            var main_thread    = Thread.CurrentThread;
            var main_thread_id = main_thread.ManagedThreadId;

            main_thread.Name = "Главный поток!";

            var timer_thread = new Thread(TimerMethod);

            timer_thread.Name         = "Поток часов";
            timer_thread.IsBackground = true;
            timer_thread.Start();

            //var printer_thread = new Thread(PrintMessage)
            //{
            //    IsBackground = true,
            //    Name = "Parameter printer"
            //};
            //printer_thread.Start("Hello World!");

            var message = "Hello World~!";
            var count   = 10;

            //new Thread(() => PrintMessage(message, count)) { IsBackground = true }.Start();

            var print_task = new PrintMessageTask(message, count);

            print_task.Start();

            //for (var i = 0; i < 10; i++)
            //{
            //    Console.WriteLine("Главный поток {0}", i);
            //    Thread.Sleep(10);
            //}



            Console.WriteLine("Останавливаю время...");

            //var curernt_process = System.Diagnostics.Process.GetCurrentProcess();
            //Process.Start("calc.exe");

            timer_thread.Priority = ThreadPriority.BelowNormal;

            __TimerWork = false;
            if (!timer_thread.Join(100))
            {
                timer_thread.Interrupt();
            }
            //if(timer_thread.IsAlive)
            //    timer_thread.Abort();

            //timer_thread.Abort(); // не работает в .NET Core
            timer_thread.Interrupt();

            Console.ReadLine();
        }
Ejemplo n.º 2
0
        public static void Start()
        {
            var mainThread   = Thread.CurrentThread;
            var mainThreadId = mainThread.ManagedThreadId;

            mainThread.Name = "главный поток";

            var timerThread = new Thread(TimerMethod);

            timerThread.Name         = "поток часов";
            timerThread.IsBackground = true;
            timerThread.Start();

            var printTask = new PrintMessageTask("In Parameter printer", 10);

            printTask.Start();

            /*
             * new Thread(() => PrintMessage("In Parameter printer", 10))
             * {
             *  IsBackground = true,
             *  Name = "Parameter printer"
             * }.Start();
             */
            /*
             * var printerThread = new Thread(PrintMessage)
             * {
             *  IsBackground = true,
             *  Name = "Parameter printer"
             * };
             * printerThread.Start("In Parameter printer");
             */



            Console.WriteLine("Останавливаю время...");

            timerThread.Priority = ThreadPriority.BelowNormal;
            _timerWork           = false;
            if (!timerThread.Join(100))
            {
                timerThread.Interrupt();
            }
            //var current_process = System.Diagnostics.Process.GetCurrentProcess();
            //Process.Start("calc.exe");
        }