Forum   Search   Register   Log in SUPERJER FORA
 

Threading

Pages: [1]
Programming Help
sprinkles

Chrome Whore
2009 Sep 6 • 2431
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.).
...then I got some ap, and shot a big ass lazar at everyone.
    2010 May 18 at 00:39
Down Rodeo
Cap'n Moth of the Firehouse

Find the Hole II Participation Medal
2007 Oct 19 • 5258
57,583 ₧
Presumably you're calling some thread exit code then, no?
Everyone stares when you walk in the room, they stare when you go....
    2010 May 18 at 03:55
sprinkles

Chrome Whore
2009 Sep 6 • 2431
10 ₧
No, all I do is call
C# code
thread.start();
.
It does what it needs to then the thread terminates.
...then I got some ap, and shot a big ass lazar at everyone.
    2010 May 18 at 10:02
Down Rodeo
Cap'n Moth of the Firehouse

Find the Hole II Participation Medal
2007 Oct 19 • 5258
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.
Everyone stares when you walk in the room, they stare when you go....
    2010 May 18 at 10:06
sprinkles

Chrome Whore
2009 Sep 6 • 2431
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
...then I got some ap, and shot a big ass lazar at everyone.
    (Edited 2010 May 18 at 10:48)     2010 May 18 at 10:35
Down Rodeo
Cap'n Moth of the Firehouse

Find the Hole II Participation Medal
2007 Oct 19 • 5258
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?
Everyone stares when you walk in the room, they stare when you go....
    2010 May 18 at 10:52
sprinkles

Chrome Whore
2009 Sep 6 • 2431
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.
...then I got some ap, and shot a big ass lazar at everyone.
    2010 May 18 at 11:06
superjer
superjer

2005 Mar 20 • 3742
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.
    (Edited 2010 May 19 at 19:26)     2010 May 19 at 19:24
Down Rodeo
Cap'n Moth of the Firehouse

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

2007 Nov 6 • 2068
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
    (Edited 2010 May 20 at 04:00)     2010 May 20 at 04:00

Pages: [1]
Forum and design copyright © 2008-2010 SuperJer.com