zoukankan      html  css  js  c++  java
  • 菜鸟 也谈谈多线程

    做开发快一年了,大部分都是有的dan线程,也从来没有考虑去去多线程处理一些东西。今天突然 看到 petshop的多线程 代码就贴出来吧

     static void Main() {


                Thread workTicketThread;
                Thread[] workerThreads = new Thread[threadCount];


                for (int i = 0; i < threadCount; i++) {


                    workTicketThread = new Thread(new ThreadStart(ProcessOrders));


                    // Make this a background thread, so it will terminate when the main thread/process is de-activated
                    workTicketThread.IsBackground = true;
                    workTicketThread.SetApartmentState(ApartmentState.STA);


                    // Start the Work
                    workTicketThread.Start();
                    workerThreads[i] = workTicketThread;
                }


                Console.WriteLine("Processing started. Press Enter to stop.");
                Console.ReadLine();
                Console.WriteLine("Aborting Threads. Press wait...");


                //abort all threads
                for (int i = 0; i < workerThreads.Length; i++) {


                    workerThreads[i].Abort();
                }


                Console.WriteLine();
                Console.WriteLine(totalOrdersProcessed + " Orders processed.");
                Console.WriteLine("Processing stopped. Press Enter to exit.");
                Console.ReadLine();
            }

  • 相关阅读:
    设置GridView、DataGrid 以提供thead、tbody等标签
    SqlCommandBuilder 可批量新增与修改数据
    js中的截流
    react代码分离方案
    redux在react中的使用
    react 生命周期
    react 函数bind(this)的三种方式
    react 三种组件定义方式
    linux系统下nginx安装目录和nginx.conf配置文件目录
    react component lifecycle
  • 原文地址:https://www.cnblogs.com/Traner/p/2819995.html
Copyright © 2011-2022 走看看