zoukankan      html  css  js  c++  java
  • 简单的线程Thread使用

    static void Main(string[] args)
    {
    for (int i = 0; i < 5; i++)
    {
    aa a = new aa();
    a.age = i;
    Thread thread = new Thread(new ThreadStart(a.getNum)); //参数和方法写到一个类里面也可以传参
    thread.Start();

    Thread.Sleep(2000);
    }
    }
    public static void getNum(object i)
    {

    Console.WriteLine(((aa)i).age.ToString());
    Console.ReadKey();
    }

    public class aa {
    public string name { get; set; }
    public int age { get; set; }
    public void getNum()
    {
    Console.WriteLine(age.ToString());
    Console.ReadKey();
    }
    }

    2.带参数的

    static void Main(string[] args)
    {
    for (int i = 0; i < 5; i++)
    {
    aa a = new aa();
    a.age = i;
    Thread thread = new Thread(new ParameterizedThreadStart(getNum)); //这么写可以在getNum里设断点
    thread.Start(a);//参数

    Thread.Sleep(2000);
    }
    }

  • 相关阅读:
    The requested resource (/) is not available解决办法
    字符问题
    Unknown column in 'field list'
    table 和 div 简单布局
    css简介
    div 与 table 的优点
    瞎搞
    html
    小计--关联 复制表结构
    ddl dml dcl
  • 原文地址:https://www.cnblogs.com/zhang-wenbin/p/8807612.html
Copyright © 2011-2022 走看看