problem with threads

  • Thread starter Thread starter _nabuchodonozor
  • Start date Start date
N

_nabuchodonozor

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??
 
Hi, take look at AutoResetEvent & ManualResetEvent classes ... it could be
that what you need here.
 
_nabuchodonozor said:
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.
 
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;/
 
Back
Top