Threading

Threading

sprinkles

Chrome Whore
2009 Sep 6 • 2547
10 ₧
Is there a way I can have a thread not terminate?

I want the audio player of WhiteBird to have its own thread, so it can run (and crash) independently of WhiteBird. So I create a new thread for it, simple. The problem is that once the thread does one thing it terminates. I need the thread to say play music, then wait around for something to do (like the thread pool). I don't want to use the thread pool simply because it is performing other tasks (navigating web pages, i/o, etc.).
 
 
 
2010 May 18 at 07:39 UTC
Down Rodeo
Cap'n Moth of the Firehouse

Find the Hole II Participation Medal
2007 Oct 19 • 5486
57,583 ₧
 
 
 
2010 May 18 at 10:55 UTC
sprinkles

Chrome Whore
2009 Sep 6 • 2547
10 ₧
No, all I do is call
C# code
thread.start();
.
It does what it needs to then the thread terminates.
 
 
 
2010 May 18 at 17:02 UTC
Down Rodeo
Cap'n Moth of the Firehouse

Find the Hole II Participation Medal
2007 Oct 19 • 5486
57,583 ₧
My advice then is to read the documentation on the thread type you're using. It seems to me that the method does most of the work for you (not trying to suggest you're in some way lacking), so when you start it up it does its thing then goes, and you're not being given much choice over how to do it. So, see if the docs tell you how to stop that/do it properly.
 
 
 
2010 May 18 at 17:06 UTC
sprinkles

Chrome Whore
2009 Sep 6 • 2547
10 ₧
Now I am confused, everybody (msn, codeproject, c-sharpcorner, etc.) tell you how to start a thread, lock, pulse, suspend, abort, etc. but they do not tell you why a thread closes automatically.

Here is some sample code that I had:
code
Thread tNavigate = new Thread(new ThreadStart(Navigate));

private void Navigate()
{
WebBrowser thiswebbrowser = GetCurrentWebBrowser();
thiswebbrowser.Navigate(TSCBurl.Text);
}


Whoops!

This is what I get:
Quote:
See the end of this message for details on invoking
just-in-time (JIT) debugging instead of this dialog box.

************** Exception Text **************
System.Threading.ThreadStateException: Thread is running or terminated; it cannot restart.
at System.Threading.Thread.StartupSetApartmentStateInternal()
at System.Threading.Thread.Start(StackCrawlMark& stackMark)
at System.Threading.Thread.Start()
at WhiteBird.Form1.TSSBmenu_ButtonClick(Object sender, EventArgs e) in C:\Users\Sprinkles\documents\visual studio 2010\Projects\WhiteBird\WhiteBird\Form1.cs:line 103
 
 
 
2010 May 18 at 17:35 UTC — Ed. 2010 May 18 at 17:48 UTC
Down Rodeo
Cap'n Moth of the Firehouse

Find the Hole II Participation Medal
2007 Oct 19 • 5486
57,583 ₧
Fancy posting form.cs? I don't know enough about your implementation to say whether it's thread safe of even sensible yet! How much have you looked at threading?
 
 
 
2010 May 18 at 17:52 UTC
sprinkles

Chrome Whore
2009 Sep 6 • 2547
10 ₧
I've look at like 12-15 documents, and they all say do it like that.

MSDN
c-sharpcorner
Yoda Its like forever long.
 
 
 
2010 May 18 at 18:06 UTC
SuperJer
Websiteman

2005 Mar 21 • 6666
Your thread is exiting because it is reaching the end of your function Navigate().

If you don't want it to exit then it needs to loop forever instead. Of course that is a good way to use 100% of your CPU unless you have it sleep and/or poll for events as it loops.

Really you shouldn't be messing with threads at all, I think. Threads are extremely difficult and not necessary. I wouldn't recommend threads to anyone but seasoned pros, and even then they should only be used when there's a really good reason.

You need to learn and truly understand concurrency, race conditions, critical sections, semaphores, resource deadlock, volatile memory and a swarm of other highly advanced topics before you can safely use threads. And I'm sure you have plenty of more important things to try and learn first; things that this thread stuff is dependent on anyway.
 
 
 
2010 May 20 at 02:24 UTC — Ed. 2010 May 20 at 02:26 UTC
Down Rodeo
Cap'n Moth of the Firehouse

Find the Hole II Participation Medal
2007 Oct 19 • 5486
57,583 ₧
 
 
 
2010 May 20 at 10:45 UTC
SRAW
Rocket Man

2007 Nov 6 • 2525
601 ₧
Down Rodeo said:
Supes has a point.


He always has a point, and thus he wins the medal of least retarded person here (the most is probably fedex)
Free Steam Games
 
 
 
2010 May 20 at 11:00 UTC — Ed. 2010 May 20 at 11:00 UTC
shalini
*** BANNED ***
2016 May 14 • 1
this game forum is the best and it is really good thanks for posting this forum

USER WAS BANNED FOR THIS POST
 
 
 
2016 May 14 at 10:41 UTC
Page [1]