处理 Windows Mobile Click 事件,使其不会“排队”当我的程序被阻塞时

发布于 2024-08-26 01:22:24 字数 1350 浏览 4 评论 0原文

我为 WinMo 6.x 编写了一个简单的应用程序来娱乐我的女儿。它保存一组动物图像与动物噪声对,并随机显示其中一个图像。单击图像时,会播放动物噪音,两岁的孩子会分心:-),然后显示下一张图像。

然而,由于她倾向于猛击屏幕,因此实际流程是图像显示后她点击了几次;播放几种动物的声音,然后图像变为下一个随机动物。

我的猜测是,操作系统正在对点击事件进行排队,而程序在播放噪音时会被阻塞,然后尽快处理它们。就像您可以在机器挂起时继续打字一样,并且当所有内容再次清除时显示文本。

因此,该表单有两个变量,

Private thisCollectionOfThings As ObjectStore
Private currentObject As RealWorldObject

ObjectStore 是 List(Of RealWorldObject) 的包装类,它具有 getNextObject 方法,该方法返回随机 RealWorldObject,并检查最近是否未返回特定对。

在我们的表单中...

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

您可以看到我尝试删除事件处理程序来尝试避免点击排队问题,但它不起作用。

任何关于如何避免这种情况的建议都将非常感激...否则我会尝试在图片框控件周围编写自己的包装器来尝试处理点击,但如果其他人的经验表明我不愿意浪费我的时间那没有帮助。

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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

独木成林 2024-09-02 01:22:24

我会为了简单起见(KISS):

  1. 使用一个名为“IsPlaying”的布尔值,并在播放声音之前将其设置为 true ,在播放完成后将其设置为 false 。
  2. 将音频播放放在后台线程中,以便 UI 保持响应。
  3. 如果该布尔值为 true,则忽略点击处理程序中的屏幕点击。

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.
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文