By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
435,105 Members | 2,560 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 435,105 IT Pros & Developers. It's quick & easy.

problem with threads

P: n/a
Hi, its me again:P

I'm writing my own mp3 player. I have loop which looks:
while (trackBar1.Value != TrackLength)
{
TrackBar1.Value = TrackPosition();
}

This loop set position to the TrackBar and when finishes a next track
is played from the palylist. Everything works correct but the loop
blocks whole program and I have to wait till it finishes. I cannot
change track when loop is working cuz program then not responding. I
thought that threads could help here. I create new Thread:
t1 = new Thread(new ThreadStart(Play)); where I put the method with
this loop. I set t1.isBackground = true; In method playAnotherSong() i
set t1.Abort(); but nothing has changed;/ I have to somehow break this
"while" if I want to play different song. What should I do??

Jun 8 '07 #1
Share this Question
Share on Google+
3 Replies


P: n/a

"_nabuchodonozor" <kk******@wsb-nlu.edu.plwrote in message
news:11**********************@q66g2000hsg.googlegr oups.com...
Hi, its me again:P

I'm writing my own mp3 player. I have loop which looks:
while (trackBar1.Value != TrackLength)
{
TrackBar1.Value = TrackPosition();
}

This loop set position to the TrackBar and when finishes a next track
is played from the palylist. Everything works correct but the loop
blocks whole program and I have to wait till it finishes. I cannot
change track when loop is working cuz program then not responding. I
thought that threads could help here. I create new Thread:
t1 = new Thread(new ThreadStart(Play)); where I put the method with
this loop. I set t1.isBackground = true; In method playAnotherSong() i
set t1.Abort(); but nothing has changed;/ I have to somehow break this
"while" if I want to play different song. What should I do??
Set a timer (since you're dealing with multimedia, timer is fully
appropriate) for a 50ms period or so, and put the logic you already showed
inside the Tick handler. There's no good reason to add the complication of
an extra thread.
Jun 8 '07 #2

P: n/a
Hi, take look at AutoResetEvent & ManualResetEvent classes ... it could be
that what you need here.

"_nabuchodonozor" <kk******@wsb-nlu.edu.plwrote in message
news:11**********************@q66g2000hsg.googlegr oups.com...
Hi, its me again:P

I'm writing my own mp3 player. I have loop which looks:
while (trackBar1.Value != TrackLength)
{
TrackBar1.Value = TrackPosition();
}

This loop set position to the TrackBar and when finishes a next track
is played from the palylist. Everything works correct but the loop
blocks whole program and I have to wait till it finishes. I cannot
change track when loop is working cuz program then not responding. I
thought that threads could help here. I create new Thread:
t1 = new Thread(new ThreadStart(Play)); where I put the method with
this loop. I set t1.isBackground = true; In method playAnotherSong() i
set t1.Abort(); but nothing has changed;/ I have to somehow break this
"while" if I want to play different song. What should I do??

Jun 8 '07 #3

P: n/a

Could you be more specific?? I am begginer with threads;/ if you could
give me an example how to simply use threads in WinForm cuz I know
that there are some differences with console app. Timer is not valid
here I've tried however perhaps you have different kind of use it....
I'm in deadlock;/

Jun 8 '07 #4

This discussion thread is closed

Replies have been disabled for this discussion.