Thread On/Off - Can't kill a thread/Thread state unknown

Hello,

I am likely not understanding threads. Below is a screen grab of a simple program. The program begins and nothing has started. Press the ‘Start Thread 1’ button and the music plays in the background and the button action shows ‘Pressed Run’, and Thread State shows ‘Not Running’ even though it is running. Press ‘Recheck Thread State’ button to update the label - nothing changes. Press the ‘Show ‘Test’’ button and the label changes to Test.

If I press the ‘Start Thread 1’ button again, there are now two versions of background music playing at the same time on the same thread that should have been killed.

Below is the download link for the program.

Download 2.21 MB

Yes, I can start and stop the music on its own. I thought that killing a thread with playing music will also stop the music - I understand that this is not the correct way to stop sound.

What am I missing to be able to kill, suspend, sleep, and resume a thread, while viewing the thread state? Thanks for your help with this noobie question…

Sorry don’t have time to look at code, but are you perhaps missing a yield statement?

Hi James,

There was no yield statement. Thanks for mentioning this. Just for fun, I sprinkled yield threads throughout the demo program, and I am not able to get or set the state of the thread once it is running.

Hi James,

You were right. One call to App.YieldToNextThread was not enough, and it works when wrapping in a While-Wend Loop

While True App.YieldToNextThread Wend

Thanks!

For those who read this post in the future, here is the modified Thread1.Run Code. All other code remains the same.

[code] Dim s As Sound
s=GameBackground
s.play

While True
App.YieldToNextThread
Wend[/code]