开发者

Handle Windows Mobile Click event so that it doesn't "queue" while my program is blocking

开发者 https://www.devze.com 2022-12-24 20:46 出处:网络
I\'ve written a simple application for WinMo 6.x to entertain my daughter. It holds a set of animal image to animal noise pairs and randomly displays one of the images. When the image is clicked the a

I've written a simple application for WinMo 6.x to entertain my daughter. It holds a set of animal image to animal noise pairs and randomly displays one of the images. When the image is clicked the animal noise plays and the two year old is distracted :-) and then the next image is displayed.

However, since she tends to bash at the screen the actual flow is that the image displays and she clicks several times; several animal noises are played and then the image changes to the next random animal.

My guess is that the OS is queueing the click events while the program is blocking as it plays the noise and then processing them as soon as it can. In much the same way as yo开发者_如何学运维u can carry on typing while your machine hangs and the text displays when everything clears again.

So the form has two variables

Private thisCollectionOfThings As ObjectStore
Private currentObject As RealWorldObject

ObjectStore is a wrapper class around a List(Of RealWorldObject) that has a getNextObject method that returns a random RealWorldObject having checked that particluar pair hasn't been returned recently.

In the form we have...

Private Sub picBox_Click(ByVal sender As Object, ByVal e As EventArgs)
            RemoveHandler picBox.Click, AddressOf picBox_Click
            picBox.BackColor = Color.Gray
            If currentObject.getSoundLocation() <> "" Then
                currentObject.playSound()
                refreshScreen()
            End If
End Sub

Private Sub refreshScreen()
    picBox.Image = Nothing
    currentObject = thisCollectionOfThings.getNextObject()
    If Not currentObject Is Nothing Then addImage()
    AddHandler picBox.Click, AddressOf picBox_Click
End Sub

Private Sub addImage()
    picBox.Image = New Bitmap(currentObject.getImageLocation())
End Sub

You can see I've resorted to trying to remove the event handler to try and avoid the click queueing issue but it isn't working.

Any advice on how to avoid this would be super-appreciated... Otherwise I'll try writing my own wrapper around the picture box control to try and handle the click but I'm loathe to use up my time if someone else's experience suggests that wouldn't help.


I'd go for simplicity (KISS):

  1. Use a boolean value called something like "IsPlaying" and set it to true right before you play the sound and false after it's done.
  2. Put the audio playing in a background thread so the UI remains responsive.
  3. If that boolean is true, ignore screen taps in the click handler.
0

精彩评论

暂无评论...
验证码 换一张
取 消