【C#】多线程的使用

首先在项目头添加:using System.Threading;

一、启动线程
1 .在按钮中启动线程

  ThreadStart threadStart = new ThreadStart(Calculate1);//通过ThreadStart委托告诉子线程执行什么方法  
  
  Thread thread = new Thread(threadStart);
  
  thread.Start();//启动线程1

2 .添加子线程函数

  public static void Calculate1()
  {
    
    //添加所需要的检测代码
    
  }

二、关闭线程

  thread.Abort();//调用Thread.Abort方法试图强制终止thread线程  

其他知识点:

子线程与主线程共用变量:

public static HTuple hv_ExpDefaultWinHandle;
在这里插入图片描述

发布了74 篇原创文章 · 获赞 24 · 访问量 3万+

猜你喜欢

转载自blog.csdn.net/weixin_43197380/article/details/103773518