C#Thread 线程的简单使用
来源:互联网 发布:足彩大数据 编辑:程序博客网 时间:2024/05/18 00:02
//*****************************************/// <summary>/// General method.2017.../cyl/// </summary>///*****************************************using UnityEngine;using System.Collections;using System.Threading;public class TestScriptThread : MonoBehaviour{ // Use this for initialization void Start () {// Method1 ();// Method2 ();// Method3 ();// Method4(); Method5 (); } //获取线程名字 void Method1 () { Thread th = Thread.CurrentThread; th.Name = "1号线"; Debug.Log ("当前线程名字: " + th.Name); } //线程启动/创建 void Method2 () { ThreadStart childref = new ThreadStart (Method1); Debug.Log ("in main: createing the child thread!"); Thread th = new Thread (childref); th.Start (); Debug.Log ("thread is start"); } //线程开启和睡眠 void Method3 () { ThreadStart childref = new ThreadStart (Method3Event); Thread th = new Thread (childref); th.Start (); } void Method3Event () { Debug.Log ("子线程开启"); int sleepfor = 5000; Debug.Log ("子线程要睡眠" + (sleepfor / 1000) + "秒"); Thread.Sleep (sleepfor); Debug.Log ("子线程重新挂起"); } //线程销毁捕获异常 void Method4 () { ThreadStart childref = new ThreadStart (Method4Event); Thread th = new Thread (childref); th.Start (); Debug.Log ("线程暂停2秒"); Thread.Sleep (2000); Debug.Log ("现在终止子线程"); th.Abort (); } void Method4Event () { try { Debug.Log ("子线程开启运行"); for (int i = 0; i < 10; i++) { Thread.Sleep (500); Debug.Log ("当期下标 " + i.ToString ()); } Debug.Log ("子线程运行完成!"); } catch (System.Exception ex) { Debug.Log ("线程终止异常"); } finally { Debug.Log ("没有抓找线程异常"); } } void Method5 () { //不带参数方法调用 Thread t1 = new Thread (new ThreadStart (Method5Event)); //带参数方法调用 Thread t2 = new Thread (new ParameterizedThreadStart (Method5Event)); t1.IsBackground = true; t2.IsBackground = true; t1.Start (); t2.Start ("hello world!"); } void Method5Event() { Debug.Log ("不带参数的线程函数"); } void Method5Event(object data) { string datastr = (string)data; Debug.Log ("带参数的线程,参数为: " + datastr); }}
0 0
- C#Thread 线程的简单使用
- Thread线程简单使用
- C#Thread 使用后台 线程定时刷新 线程的使用 Thread的使用
- 线程thread的使用
- py使用thread的一个简单的线程同步编程
- Linux线程的thread.c
- C#Thread的使用
- thread包 一个简单的线程实例
- windows thread的简单使用
- 一个简单的例子解析android中Handler线程和普通Thread的使用
- 【c++】线程thread类
- C++/MFC-线程Thread
- C++:线程(std::thread)
- Android中线程Thread的使用
- C++11中thread线程的使用
- php中关于线程thread的使用
- linux编程 - C/C++每线程(thread-local)变量的使用
- 使用Thread创建线程
- 数据库锁机制
- 安卓的开发网站
- cocos2d-x嵌入android的camera 实现前后摄像头的预览和保存
- 自定义 iOS 密码框或验证码输入框,支持多位验证码,4位或6位验证码自己选择。
- 白书贪心3题,poj2376\1328\3190
- C#Thread 线程的简单使用
- 解决React-Native reload hot reloading 后代码不更新问题
- Caused by: java.lang.ClassNotFoundException
- Struts2的学习(5)-PrepareInterceptor
- 文件大小转换工具Formatter.formatFileSize(MainActivity.this, bitmap.getByteCount())
- Spring Boot CLI安装(WIN10环境)
- 移动端页面撑满屏幕宽高,css设置
- SQL的学习笔记
- mysql数据库 在windows上定时备份