Re: Delay in execution when Button is clicked.



Treadstone 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);

//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.

You have a loop for reading the file, and you have a loop for refilling the array. Do you understand that any time your program is looping it will not process a button click message? In a GUI program it is generally necessary to avoid lengthy loops, or to execute them in a separate thread, so the GUI will remain ready to process user input.

--
Scott McPhillips [VC++ MVP]

.