zoukankan      html  css  js  c++  java
  • C#基础学习之同步线程的补充

    同步委托线程是没有返回值的,可以有一个Object类型的参数,也可以没有参数

    同步委托线程有参数时:  Thread thread = new Thread(test)这样创建的同步线程必须有一个object类型的参数
    参数是通过start()方法传给委托方法的

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    using System.Threading;
    using System.Threading.Tasks;
    
    namespace 同步线程
    {
        class Program
        {
            static void Main(string[] args)
            {
                Thread thread = new Thread(test);//创建同步线程
                thread.Start(10);//将参数传入委托方法中
                Console.ReadKey();
            }
            static void test(object a)//委托方法,只能通过start传入一个Object类型的参数
            {
                Console.WriteLine(a);
            }
        }
    }

    同步委托线程没有参数时:Thread thread = new Thread(new ThreadStart(test));//创建同步线程,不能向委托方法传参数

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    using System.Threading;
    using System.Threading.Tasks;
    
    namespace 同步线程
    {
        class Program
        {
            static void Main(string[] args)
            {
                Thread thread = new Thread(new ThreadStart(test));//创建同步线程,不能向委托方法传参数
                thread.Start();
                Console.ReadKey();
            }
            static void test()//委托方法
            {
                Console.WriteLine("a");
            }
        }
    }

    同步委托线程传入的方法既可以是静态方法,也可以是非静态方法

  • 相关阅读:
    Django(60)Django内置User模型源码分析及自定义User
    Django(59)验证和授权
    Django(58)viewsets视图集详解
    Django(57)Generic类视图
    正则表达式
    JMeter之检查点(JSON断言)
    JMeter之检查点(响应断言)
    JMeter之参数化(一)
    JMeter之一个简单的性能测试
    JMeter基础
  • 原文地址:https://www.cnblogs.com/zhangyang4674/p/11414374.html
Copyright © 2011-2022 走看看