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

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

  • 相关阅读:
    c#大文件上传解决方案支持分片断点上传
    css精灵动画
    文字游戏
    利用myeclipse配置数据库连接池
    python 简单的txt文件读写
    数据库连接池配置
    hdu 1030 Delta-wave
    java jdbc sqlhelper
    js实现页面的自动读秒跳转
    购物车模块
  • 原文地址:https://www.cnblogs.com/zhangyang4674/p/11414374.html
Copyright © 2011-2022 走看看