I tried that and it did not work. They get buffered I think. I will try to
illustrate what is happening with some pseudocode;
1) The method StartSound() essentially hides button and starts sound output.
(see below)
class Test : Control
{
void StartSound()
{
button.visible=false
button.enabled=false
refresh();
soundclass.PlaySound()
}
}
2A) The method soundclass.PlaySound() signals a SoundVisualizer class that
it has started to
play sound via EventHandler in SoundVisualizer::SoundEventHandler(object
s, SoundEventArgs e).
class SoundVisualizer
{
void SoundEventHandler(object s, SoundEventArgs e)
{
startSoundProgressBar()
ShowButtonEventHandler()
}
}
2B) SoundVisualizer::SoundEventHandler(object s, SoundEventArgs e) starts
progress bar animation
and via event handler in Test class, tells it to show 'button'.
class Test : Control
{
void ShowButtonEventHandler(object s, SoundEventArgs e)
{
button.visible=true;
button.enable=true;
}
}
3A) A little information, in Test class when button is pressed I stop the
Sound and Visualization
animation and do business logic and then start sequence again.
3B) In class SoundClass the method PlaySound() goes into a loop to send data
to a external
device via bluetooth. During this loop everything is blocked, nature of
bluetooth library
that is being used I don't like it but is what I have to work with. Well,
because of this,
if user presses button once everything is fine I process and move on.
However, if it is
pressed multiple times multiple MouseDown events and when Test get it's
chance to run it
processes all of them. This is wrong, because thet next sound is stopped
before it is started.
class SoundClass
{
public PlaySound()
{
// ... other code to get stuff started.
while (!playSoundCancelled && (bytesRead = fs.Read(data, 0,
DATA_CHUNK_SIZE)) != 0)
{
Application.DoEvents();
bluetooth.SendAudio(data, bytesRead);
}
}
}
I tried adding flags to this does not synchronize well and I can not use
syncrhonize() because of
timing issues with device. I am thinking that MouseDown events get queued by
system and when
Application.DoEvents() is called in SOundClass
laySOund() loop Test class
get a burst of them
and processes each one of them.
My solution is on button handler is to forget any pending MouseDown events
or flush them.
I hope this clears up why I am doing this.