zoukankan      html  css  js  c++  java
  • C#多线程传参

        class test
    {
    private int i ;
    private string s;
    public test(int n1,string s1)
    {
    this.i = n1;
    this.s = s1;
    }
    public void Withparameters()
    {
    Console.WriteLine("线程启动,参数{0},{1}",i,s);
    }
    }
    class Program
    {
    static void Main()
    {
    Thread th = new Thread(new ParameterizedThreadStart(WithParameters));//使用parameterizedThreadStart能传递一个object参数。可以对object参数进行转化,实现多个参数传递
    th.Start("ParameterizedthreadStart");
    test t=new test(123,"参数");//自定义类可传递多个参数
    Thread th1 = new Thread(t.Withparameters);
    th1.Start();
    Thread th2 = new Thread(() => WithParameters("lambda"));//lambda匿名方法可传递多个参数。
    th2.Start();
    Console.ReadKey();
    }
    static void WithParameters(object obj)
    {
    string o = obj as string;
    if (!string.IsNullOrEmpty(o))
    {
    Console.WriteLine("线程启动,参数{0}",o);
    }
    }
    }
  • 相关阅读:
    模板类 & 虚函数
    Page Color (页面着色)
    修改静态库
    ElementUI 时间选择器
    自定义export
    vue组件
    ElementUI 表格
    ElementUI 分页
    数组方法分类
    Vue过滤数组副本
  • 原文地址:https://www.cnblogs.com/smailxiaobai/p/2271626.html
Copyright © 2011-2022 走看看