进程、多线程

进程

  整个公司 - 一个进程 - 一个程序

  Process.Start("");

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Diagnostics;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;//1引用命名空间

namespace WindowsFormsApplication5
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            //Process.Start("calc");//calc计算器括号内内要打卡的程序名字符串型的
            //Process.Start("Chrome","http://www.baidu.com");//用谷歌的浏览器打开
            //Process.Start("http://www.baidu.com");//用用户电脑默认的浏览器打开
            Process.Start(textBox1.Text);//4、打开
        }

        private void button2_Click(object sender, EventArgs e)
        {
            //浏览并打开应用程序
            //1、在from1中一个浏览按钮一个打开按钮一个TextBox用于接收浏览的路径和一个OpenFileDialog
            openFileDialog1.Filter = "应用程序|*.exe";//3、只能看应用程序
            DialogResult dr = openFileDialog1.ShowDialog();
            if (dr == DialogResult.OK)//2、如果点的是确定将选中的文件在textBox1.Text显示出来
            {
                textBox1.Text = openFileDialog1.FileName;
            }
        }
    }
}

线程

  默认程序中只有一个线程 - 公司老板

  同一时间只能做一件事 主线程 - 老板

  线程 - 公司中的员工,临时工

1、启用线程

  引用命名空间:using System.Threading;

  Thread th = new Thread(Test1);

  th.Start();

2、主线程/进程关闭后,子线程不会立刻退出

  默认线程都是前台线程

  把前台线程变为后台线程

    th.IsBackground = true;

3、默认是不允许跨线程访问

  关闭监控

    Control.CheckForIllegalCrossThreadCalls = false;

4、只开启一个线程

     让按钮不可用

    中间变量判断

5、中止线程

  th.Abort();

原文地址:https://www.cnblogs.com/skyhorseyk/p/7209953.html