当前位置:网站首页>Unity write multithreading considerations

Unity write multithreading considerations

2022-06-21 08:21:00 kuilaurence

 Insert picture description here
First step :
using System.Threading; // Import header file
The second step :

private Thread threads;                     // Sub thread 
void Start(){
    
	threads = new Thread(SendMsg);
	threads.Start();
}
private void SendMsg()                      // write in 
{
    
    Thread.Sleep(500);					    // Child thread delay 0.5s
    Debug.log("hello world!");
}
public void OnDestroy()                      // Automatically destroy child threads on shutdown or exit 
{
    
    if (threads != null) {
     threads.Abort(); }
}

tips: Cannot get in child thread Application.persistentDataPath;
It can be like this :

 string persistent = "";
 void Start(){
    
 	persistent = Application.persistentDataPath;
 }
 ...
 ...
 void SendMsg(){
          // The method that the child thread runs 
 	string path=persistent+"/test.txt";
 	...
 	...
 }
原网站

版权声明
本文为[kuilaurence]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/172/202206210819215249.html