Single threading problem

A

Asheesh

Hi All,

I'd be grateful if someone could help me out. I'm developing an application
in which a user answers a particular set of questions in a given interval.
The time interval can vary. I'm using System.windows.Forms.Timer control for
this application.
I set the interval for the timer to 1 second, and then in it's tick event I
set a counter which I keep on increasing and display time passed in a label
in terms of a stop watch as MM:SS.

So far, so good. Now in my application whenever a user presser a right
answer, an right answer audio cue is played else a wrong answer audio cue is
played.

Now for this I'm making P/Invoke calls to audio playback function in my
audio engine library.
Now when the audio starts to play, all the execution control is transferred
to the audio playback execution, and my timer stops there. It's only when
the audio playback gets completed, it resumes its stop watch, thereby
incrementing the time.

Since my app is single threaded, this is quite logical. But I want my timer
to keep on moving, even when my audio cues are being played.

Since my audio cue is played, every time the user presses the answer, it's
not a good idea to start a thread everytime the presses the answer button.

So, I tried to make use of the ThreadPool class, thereby assigining my audio
playback function in that delegate.
This works fine for first couple of times, and then I receive a native
exception error message.

I don't understand why is it so? A reason for this could be that in my eVC++
wrapper over my audio dll, I quicky create and allocate my audio engine
object in order to play the file.

Now in case of a thread pool, it might so happen that 2 threads might try to
access the same object even before it gets released, as a result of which a
memory leak occurs.

Another way is use System.Threading.Timers, but since it would also be
create from within the main thread, it'd also face the similar problem of
hanging the execution, while my audio playback is on.

Can any one suggest some other alternative as to what should be the right
approach for mutithreading in this case.
Any help will be deeply appreciated.

Regards,
Asheesh
 
P

Peter Foot [MVP]

You can play the sound Asynchronously which will return processing to your
application while the sound plays in the background. Pass SND_ASYNC
(0x00000001) into the third parameter of the PlaySound call.

Peter

--
Peter Foot
Windows Embedded MVP

In The Hand
http://www.inthehand.com
Handheld Interactive Reference Guides
 
A

Asheesh

Thanks for your reply Peter, but I'm using XAudio library engine for playing
my mp3 files. The functions that I've wrapped in my eVC++ wrapper don't have
asynchronous execution of audio files.

Is there any other way where I can play these mp3 files on a different
thread?

Can I play MP3 files using the PlaySound function of the core WinCE API
library?
Regards,
Asheesh
 
Joined
Oct 28, 2006
Messages
1
Reaction score
0
Hi Peter,
Is XAudio library engine used for playing my mp3 files, is a Microsoft Component. Can I use it in C# for .NET Compact Framework. Is there any sample code available to play MP3 files using XAudio library engine?
Hi Asheesh,
Can you give me the code to play MP3 files using XAudio library engine?\

Thanks in Advance!!
Anil
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top