zoukankan      html  css  js  c++  java
  • 线程的几种用法

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    using System.Threading;

    namespace ConsoleApplication
    {
        class Program
        {
            static void Main(string[] args)
            {
                ////线程方法1
                //if (ThreadPool.QueueUserWorkItem(new WaitCallback(Program.WritePara), "这是传进去的参数"))
                //{
                //    Console.WriteLine("ok:");
                //    Console.Read();
                //}
                //线程方法2
                Thread th = new Thread(new ThreadStart(Write));
                th.Start();
                //线程方法3
                Thread thread = new Thread(new ParameterizedThreadStart(WritePara));
                thread.Start("Thread thread = new Thread( new ParameterizedThreadStart(WritePara))有参传递");


            }
            protected static void WritePara(object para)
            {
                Console.WriteLine("hello:" + para);
            }

            private static void Write()
            {
                Console.WriteLine(" Thread th = new Thread(new ThreadStart(Write));无参线程调用");
            }
        }
    }

  • 相关阅读:
    POJ 1062 坑爹的聘礼(枚举等级差选择性找边)
    c++ string函数详细返回值及用法!
    POJ 2240 利率变权值 Floyd变乘法
    POJ 1797 最大运载量
    API code
    编程题目的讨论
    C语言位运算符:与、或、异或、取反、左移和右移
    &与&& C语言
    反思
    CreateWindow的出错解决
  • 原文地址:https://www.cnblogs.com/yexinw/p/3532530.html
Copyright © 2011-2022 走看看