Winform(2.多线程)
主线程:创建ui的线程,所有跟UI(user interface)相关的操作都需要在主线程中完成,程序默认就是在主线程,
分线程:又叫后台线程,主要用于执行例如操作文件,网络请求等耗时的任务,不能在分线程刷新ui
Form1代码:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace _2.多线程
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
Thread thread2 = new Thread(ThreadMethod2);
thread2.Name = "子线程A";
thread2.Start();
}