zoukankan      html  css  js  c++  java
  • 多线程调用本质

    System.Threading.Thread.Sleep(0)
    和System.Threading.Thread.Sleep(100)
    100 是线程阻塞的毫秒数,表示0.1 秒,在阻塞时线程状态是 ThreadState.WaitSleepJoin
    指定0 以指示应挂起此线程以使其他等待线程先执行

    public abstract class Framework
        {
            private static bool _vbSuccess = false;
            private int _viIndex = 0;
     
            public abstract void Perform();
     
            public void Start()
            {
                Monitor();
                while(_vbSuccess)
                    System.Threading.Thread.Sleep(0);
                Console.WriteLine("Result:{0}",_viIndex);
                Perform();
            }
     
            private void Monitor()
            {
                _vbSuccess = true;
                System.Threading.Thread thread
                    = new System.Threading.Thread(DoWork);
                thread.IsBackground = true;
                thread.Name = "WT # " + DateTime.Now;
                thread.Start();
            }
     
            private void DoWork()
            {
                for (int i = 0; i < 1234567;i++ )
                {
                    _viIndex = i;
                    if (i % 99 == 0)
                        Console.WriteLine("Current:{0}",i);
                }
                _vbSuccess = false;
            }
     
        }
    public class Work:Framework
    {
        public Work()
        {
            Start();
        }
     
        public override void Perform()
        {
            Console.WriteLine("Hello");
        }
    }
     
     
    class Program
    {
        static void Main(string[] args)
        {
            Work vWork = new Work();
            Console.WriteLine("Over");
            Console.Read();
        }
    }
  • 相关阅读:
    Admin添加字段
    django admin基础
    user_admin
    admin 模块功能
    todolist项目
    Django进阶项目
    Django进阶
    bolg项目
    EL&jstl
    模拟用户登录,内含验证码验证和request等操作
  • 原文地址:https://www.cnblogs.com/hongjiumu/p/2852059.html
Copyright © 2011-2022 走看看