Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
0
Question by darknessflux · May 17, 2018 at 05:45 AM · coroutinesthreadsthreadingmultithreading

Multi threading problem !

public void SendVoice() {

     StartCoroutine(call.postWWW(lip, lipSync, sentVoiceNumber - 1));
     do
     {
          //Debug.Log(call.wwwPostRequest.isDone);

     } while (!call.wwwPostRequest.isDone);//ablabal
     
     
     if (call.wwwPostRequest.isDone)
     {

         string tempPath = Path.Combine(Application.persistentDataPath, "Audio");
         tempPath = Path.Combine(tempPath, "returnAudio.wav");



i need to multithread this while loop because it is freezing my app , but i cannot because im calling postrequest that is creating a new object in it

postrequest :

public IEnumerator postWWW(LipSync lip, LipSyncData lipSync, int i) {

     this.lip = lip;
     this.lipSync = lipSync; 
     Dictionary<string, string> headers = new Dictionary<string, string>();
     headers.Add("Content-Type", "application/octet-stream");
     string fileName = "sentRecord" + i + ".wav";
     //string fileName = "carolyne1.wma";
     byte[] byteData = File.ReadAllBytes("Assets/Audio/" + fileName); ;
     wwwPostRequest = new WWW("http://192.168.31.5:8001/voice", byteData, headers);
     yield return wwwPostRequest;
 }
Comment
Add comment · Show 1
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image Harinezumi · May 17, 2018 at 01:57 PM 0
Share

Well, you do start an infinite loop on the main thread just after you start the coroutine with call.postWWW() in it. Either start a different coroutine that waits for the result of call.wwwPostRequest (recommended way), or check it in an Update() function (not so good).

2 Replies

· Add your reply
  • Sort: 
avatar image
0

Answer by hugodeheld · May 17, 2018 at 08:48 AM

You could look into the new job system in unity 2018.1, other than that unity doesn't nativly support multi-threading. You can try it but i cant recomend it as it just crashes unity allot and will be a pain.

But if you really insist on it, this could help:
https://gamedev.stackexchange.com/questions/113096/how-to-not-freeze-the-main-thread-in-unity

Comment
Add comment · Show 2 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image bassamjuniorkh1 · May 17, 2018 at 12:20 PM 0
Share

well either way my app is freezing everytime i run the while loop you got any other options ?

avatar image bassamjuniorkh1 · May 17, 2018 at 12:22 PM 0
Share

i have already checked it out its not about multithreading its about i cannot multithread while creating an object not in the main thread .. i need an easy way to use callback for this im totally messed up right now lol

avatar image
0

Answer by Jerry-FFG · May 17, 2018 at 03:20 PM

Coroutines in unity do NOT run on a different thread !

Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

87 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Does UnityEngine.CustomeYieldInstruction works in a seperate thread? 2 Answers

Getting current time from the worker thread 1 Answer

What's the best way to structure a recursive long running algorithm? 1 Answer

Multithreading freezes editor 1 Answer

Return value from coroutine to non monobehaviour 1 Answer


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges