.NET 简单多线程

取消跨线程访问

Control.CheckForIllegalCrossThreadCalls = false;

1.开启新线程

无参数

        Thread thread = new Thread(方法名);
        thread.Start();

有参数

方法参数需要设置为Object 使用时再强转下。

        Thread thread = new Thread(方法名);
        thread.Start(参数);

2.后台线程

默认情况下创建的线程都是前台线程。只要有一个前台线程在运行,那么程序就不会退出。

当设置为后台线程后,程序中所有前台线程退出后,运行中的后台线程也会被强制停止。

thread.IsBackground = true;

3.更新UI线程

通过定义一个Action委托来执行

            Action act = delegate
            {
			  //更新操作
            };
            this.Invoke(act);

进程

1.启动程序

Process.Start("EXE文件全路径");

2.打开指定文件夹

Process.Start("explorer.exe", 文件夹路径);  

更多:C#中的多线程

posted @ 2018-04-15 13:44  -Tiger  阅读(285)  评论(0编辑  收藏  举报