Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 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
1
Question by ZowPac · Sep 16, 2013 at 07:43 PM · threadingthread

Threading and Application.isPlaying

So I'm in the editor and I think my threads (which I'm stuck with) are still running even after I hit the stop button.

I'd like to do something like this:

 #if UNITY_EDITOR
     if (!Application.isPlaying) StopEverything();
 #endif

but that Unity interface is only allowed on the "main thread".

So -

a) Am I imagining that the threads still run? I've been pretty convinced at times, and largely am just frustrated by slowness and crashes when working in the editor. But I've not read definitively that the Editor can't deal with shutting down threads that user code has started and would love for someone to (accurately) tell me I'm wrong about that.

b) Given I'm right about that, how do I have these threads shutdown gracefully on their own? If I count on something in the main thread to provide a trigger (OnApplicationQuit() or whatever), I don't feel like I can rely on that since, obviously, I'm debugging code and I can easily mess up something that isn't dead simple.

And if it's relevant, I'm stuck with 3.5 for the time being.

Comment
Add comment
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

1 Reply

· Add your reply
  • Sort: 
avatar image
1

Answer by Ejlersen · Sep 16, 2013 at 08:41 PM

Here is what I usually do, when I need to stop my threads.

• Add a bool to my threads loop. • When I abort my thread, I set the bool to false and check if its aborted properly.

Then you can from some sort of manager script stop the threads from the main thread.

Here is a guide that explains the idea in depth:

http://msdn.microsoft.com/en-us/library/7a2f3ay4(v=vs.90).aspx

Comment
Add comment · Show 3 · 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 ZowPac · Sep 16, 2013 at 09:55 PM 0
Share

That's how these threads get shut down in the normal case. I'm really looking for something simpler than that where no matter how messed up things might be elsewhere in the code, a thread can still stop itself appropriately. Checking Application.isPlaying would be ideal, but alas...

avatar image Ejlersen · Sep 17, 2013 at 03:39 PM 0
Share

Well, you could keep a static bool on the manager script, which they could check on.

avatar image Tobias Reich · Dec 09, 2013 at 10:06 PM 0
Share

I have the same problem. Unity keeps running my threads even after pressing the pause button. But I can not access the running state of my application from "outside" of my $$anonymous$$ainThread.

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

17 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

Related Questions

Has something changed with Application.isPlaying ?! 1 Answer

Thread pool or socket bug? please help,,, 0 Answers

new Thread vs StartCoroutine 2 Answers

What does new Thread do, and how many threads are too many? 1 Answer

Making calls to Spotify REST API blocks main thread 2 Answers


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