Unity3d 创建线程 子线程与主线程通信
2013-08-22 16:34
351 查看
创建子线程
一,不带参数
Thread resourcesLoadThread=new Thread (this.resourceLoadTxt);
resourcesLoadThread.Start();
void resourceLoadTxt(){
}
二,带参数;
第一种:使用ParameterizedThreadStart。
调用 System.Threading.Thread.Start(System.Object) 重载方法时将包含数据的对象传递给线程。
Thread resourcesLoadThread=new Thread (this.resourceLoadTxt);
object o="wujjjj";
resourcesLoadThread.Start(o);
void resourceLoadTxt(object str){
// 类型转换
//程序代码
}
线程间通信:
用委托事件,delegate\event
internal delegate void ResourceLoadDelegate(string textStr);
internal static event ResourceLoadDelegate resourceLoadDelegate;
Thread resourcesLoadThread;
string path="/Txt/information";
void Start () {
resourcesLoadThread=new Thread (this.resourceLoadTxt);
object o="wujjjj";
resourcesLoadThread.Start(o);
}
void resourceLoadTxt(object str){
Debug.Log(str);
if(resourceLoadDelegate!=null)
resourceLoadDelegate(str.ToString());
resourcesLoadThread.Abort();
}
一,不带参数
Thread resourcesLoadThread=new Thread (this.resourceLoadTxt);
resourcesLoadThread.Start();
void resourceLoadTxt(){
}
二,带参数;
第一种:使用ParameterizedThreadStart。
调用 System.Threading.Thread.Start(System.Object) 重载方法时将包含数据的对象传递给线程。
Thread resourcesLoadThread=new Thread (this.resourceLoadTxt);
object o="wujjjj";
resourcesLoadThread.Start(o);
void resourceLoadTxt(object str){
// 类型转换
//程序代码
}
线程间通信:
用委托事件,delegate\event
internal delegate void ResourceLoadDelegate(string textStr);
internal static event ResourceLoadDelegate resourceLoadDelegate;
Thread resourcesLoadThread;
string path="/Txt/information";
void Start () {
resourcesLoadThread=new Thread (this.resourceLoadTxt);
object o="wujjjj";
resourcesLoadThread.Start(o);
}
void resourceLoadTxt(object str){
Debug.Log(str);
if(resourceLoadDelegate!=null)
resourceLoadDelegate(str.ToString());
resourcesLoadThread.Abort();
}
相关文章推荐
- Unity3d 分别创建了两个线程客户端 服务器连接的简单示例
- Unity3d 分别创建了两个线程客户端 服务器连接的简单示例
- boost::thread线程创建方式总结
- (转)java创建线程的两种方法比较
- 线程间操作无效: 从不是创建控件“Control Name'”的线程访问它问题的解决方案及原理分析
- HandlerThread 创建一个异步的后台线程
- ACE线程管理机制-线程的创建与管理
- java线程池(3)-线程池创建新线程的过程(原理)
- Java创建线程的四种实现方式
- 使用java.util.concurrent.ThreadFactory类创建线程
- 通过继承Thread类的方式创建两个线程
- android--handler的不同线程的创建及数据传输
- 第22天 线程的创建(有栗子)
- Java线程:创建与启动
- java线程的三种创建方式对比
- 【java并发】传统线程技术中创建线程的两种方式
- 黑马程序员——java基础——Java中创建线程的两种方式
- c#线程间操作无效: 从不是创建控件“textBox1”的线程访问它
- 多线程(c++11)------创建线程
- 线程间操作无效: 从不是创建控件“textBox1”的线程访问它