C#中Thread类中Join方法的理解(转载)
- using System;
- namespace TestThreadJoin
- {
- class Program
- {
- static void Main()
- {
- System.Threading.Thread x = new System.Threading.Thread(new System.Threading.ThreadStart(f1));
- x.Start();
- Console.WriteLine("This is Main.{0}", 1);
- x.Join();
- Console.WriteLine("This is Main.{0}", 2);
- Console.ReadLine();
- }
- static void f1()
- {
- System.Threading.Thread y = new System.Threading.Thread(new System.Threading.ThreadStart(f2));
- y.Start();
- y.Join();
- Console.WriteLine("This is F1.{0}",1);
- }
- static void f2()
- {
- Console.WriteLine("This is F2.{0}", 1);
- }
- }
- }
这儿有三个线程在处理(包括主线程),大家可看看执行结果. 结果: This is Main.1 This is F2.1 This is F1.1 This is Main.2
如果: 注释// x.Join(); 结果: This is Main.1 This is Main.2 This is F2.1 This is F1.1
C#中Thread类中Join方法的理解(转载)的更多相关文章
- Java中Thread类的join方法到底是如何实现等待
现在的场景是A线程执行:public void run(){ bThread.join(0);//把b线程加入到当前线程(a线程),等待b结束,当前a线程才会结束.}B线程执行public void ...
- Thread类的join()方法
public class Demo { /** * Thread类的join()方法 * -------------------------------- * 1)join() * 2)join(lo ...
- 多线程:Thread类的Join()方法
多线程:Thread类的Join()方法 http://blog.163.com/hc_ranxu/blog/static/3672318220095284513678/ 当我们在线程B中调用Thre ...
- 对于自定义标签类中JspBody类的invoke方法的理解
下面是javaeeAPI中对于invoke()方法的介绍: 其中的参数out是一个Writer类的对象,如果写null,就是将标签体内容写到了与此jsp相关联的JspWriter对象,也就是下面的w: ...
- 【java基础】Thread类之join方法
- python语言中threading.Thread类的使用方法
1. 编程语言里面的任务和线程是很重要的一个功能.在python里面,线程的创建有两种方式,其一使用Thread类创建 # 导入Python标准库中的Thread模块 from threading i ...
- Thread类中的join方法
package charpter06; //类实现接口public class Processor implements Runnable { // 重写接口方法 @Override public v ...
- Java线程状态及Thread类中的主要方法
要想实现多线程,就必须在主线程中创建新的线程对象. 不论什么线程一般具有5种状态,即创建,就绪,执行,堵塞,终止. 创建状态: 在程序中用构造方法创建了一个线程对象后,新的线程对象便处于新建状态,此时 ...
- 多线程(Thread类中的方法线程名称)
1 package multithread; 2 3 /* 4 * 如何创建一个线程呢? 5 * 6 * 创建线程方式一:继承Thread类. 7 * 8 * 步骤: 9 * 1,定义一个类继承Thr ...
随机推荐
- Delphi 之前解析串口数据
//串口接收数据procedure TfrmClientMain.Comm1ReceiveData(Sender: TObject; Buffer: Pointer; BufferLength: Wo ...
- js获取字符串最后一个字符代码
方法一:运用String对象下的charAt方法 charAt() 方法可返回指定位置的字符. 代码如下 复制代码 str.charAt(str.length – 1) 请注意,JavaScript ...
- BF-KMP 算法
#define _CRT_SECURE_NO_WARNINGS #include<stdio.h> #include<stdlib.h> #include<string. ...
- layout相关
大致看了看布局大致有5种(approximately) 1. LinearLayout 2. RelativeLayout 3. FrameLayout 4. TableLayout 5. GridL ...
- linux 后台运行程序
有些时候,我们需要在终端启动一个程序,并使之运行--但是如果关闭终端,那么这个程序也就随着关闭了.那么有没有什么方法在关闭终端后,让已经从这个终端启动的程序继续运行呢? 前置知识: xterm,con ...
- Archlinux 踩坑实录
Archlinux 没声音 1. 排查驱动,声卡驱动没问题 2.排查alsa,alsa没问题(并确认声卡存在且取消静音) 3.抱着尝试的心态,安下VLC.然后提示找不到默认声卡设备(大概这个意思),通 ...
- 《学习OpenCV》练习题第五章第二题abc
代码: #include <stdio.h> #include <opencv/highgui.h> #include <opencv/cv.h> #include ...
- iOS 获取通讯录权限的时机
建议将获取通讯录权限的代码放到 -(void)viewDidAppear:(BOOL)animated 或 -(void)viewWillAppear:(BOOL)animated 假如放在 view ...
- 《Java数据结构与算法》笔记-CH5-链表-4用链表实现堆栈
//用链表实现堆栈 /** * 节点类 */ class LinkS { private long data; public LinkS next; public LinkS(long d) { th ...
- 'System.Web.Http.GlobalConfiguration' does not contain a definition for 'Configure'
It needs the system.web.http.webhost which is part of this package. I fixed this by installing the f ...