创建子线程

一,不带参数

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();

}

 

 

相关文章:

  • 2021-11-16
  • 2021-12-06
  • 2022-12-23
  • 2021-10-16
  • 2021-11-29
  • 2022-01-19
  • 2022-12-23
  • 2021-07-28
猜你喜欢
  • 2022-12-23
  • 2021-10-12
  • 2021-07-06
  • 2022-12-23
  • 2022-12-23
  • 2021-08-11
  • 2022-12-23
相关资源
相似解决方案