創建子線程
一,不帶參數
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();
}