Re: Delay in execution when Button is clicked.
- From: Joseph M. Newcomer <newcomer@xxxxxxxxxxxx>
- Date: Wed, 10 Jan 2007 12:35:52 -0500
See below...
On 10 Jan 2007 07:59:47 -0800, "Treadstone" <u.bhargav@xxxxxxxxx> wrote:
Hi,****
I'm developing an application using MFC that plays WAV audio files. My
user interface consists of 3 buttons - Play, Pause and Stop.
When I click the play button, my program Reads the WAV file in chunks
of 1024bytes and stores them in a static array. The array is processed
in another function and the array is refilled in a while loop.
On clicking the Pause button the file being played should be Paused.
I am facing some difficulty here. Although the play and pause are
working fine, there is a delay in execution for the "OnPauseClick".
(When the pause button is clicked).
I do not face this problem while playing a file whose size is less than
50k. If I play a file that is around 500k, the delay is quite
significant i.e. the Pause button gets activated about 5secs after it
has been clicked.
Is there a problem with my buffer handling? (the way I read my file and
store it into an array)
I have attached just the buffer handling code below:
do{
ReadFile(hFile, <Pointer to array>, 1024, &NoOfBytesRead, NULL);
ProcessArray(Array);
}while(NoOfBytesRead > 0);
Where is this loop? If it is not in a separate worker thread, you are screwed. This is
because as long as this loop is running in the main GUI thread, a button click cannot be
seen. If it is in a secondary thread, you should have some way to detect that the button
has been activated in the GUI thread, and suspend processing; I see nothing in this code
that does it (it could also be in the ProcessArray handler, but you don't explictly say
that)
****
****
//Code that processes the array
void ProcessArray(char *)
{
...
...
}
Or does it have something to do with MFC? And yes, I have been testing
this on the emulator.
It almost certainly has to do with the architecture of your program, but you give
insufficient information to analyze that. I'm just guessing that you have made the
classic error of a long-loop-in-the-GUI-thread.
joe
****
Joseph M. Newcomer [MVP]
Regards,
Treadstone
email: newcomer@xxxxxxxxxxxx
Web: http://www.flounder.com
MVP Tips: http://www.flounder.com/mvp_tips.htm
.
- Follow-Ups:
- Re: Delay in execution when Button is clicked.
- From: Treadstone
- Re: Delay in execution when Button is clicked.
- References:
- Delay in execution when Button is clicked.
- From: Treadstone
- Delay in execution when Button is clicked.
- Prev by Date: Re: Comport problems
- Next by Date: GetGlyphOutline API
- Previous by thread: Re: Delay in execution when Button is clicked.
- Next by thread: Re: Delay in execution when Button is clicked.
- Index(es):
Loading