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();
            }

  • 相关阅读:
    5、文件处理
    6、Python模块
    4、字典使用
    3、列表 list
    1、Python基础
    2、循环判断
    配置LOG4J(log4j-1.2.17)
    File /WEB-INF/web.xml not found...
    关于TOMCAT的 ROOT/WEB-INF/web.xml的配置
    tomcat 配置系列3
  • 原文地址:https://www.cnblogs.com/Traner/p/2819995.html
Copyright © 2011-2022 走看看