1

我正在为 Windows Phone 开发一个应用程序。我的问题是如何在 2 秒后触发事件?

    Private Sub btn1_Click(sender As Object, e As RoutedEventArgs) Handles btn1.Click
    Dim input As String = txtinput.Text
    Dim last As Char = input(input.Length - 1)
    If last = "A" Then
        Dim final As String = input.Substring(0, input.Length - 1) & "B"c
        txtinput.Text = final.

      'start timer here
      'trigger an event after 2 seconds

    ElseIf last = "B" Then
        Dim final As String = input.Substring(0, input.Length - 1) & "C"c
        Dim tmr As TimeSpan = TimeSpan.FromSeconds(2)
        txtinput.Text = final

      'start timer here
      'trigger an event after 2 seconds


    Else
        txtinput.Text = input + "A"
    End If

 End Sub

我使用 Visual Basic 作为我的语言来开发它。任何帮助将非常感激。

4

2 回答 2

2

在类中声明 dispatcherTimer

Dim WithEvents dt As System.Windows.Threading.DispatcherTimer

然后根据需要创建 dispatcherTimer 的实例,设置时间跨度

dt = New System.Windows.Threading.DispatcherTimer()
dt.Interval = New TimeSpan(0, 0, 0, 0, 500) '' 500 Milliseconds
dt.Start()

这是你的处理程序

Private Sub dt_Tick(ByVal sender As Object, ByVal e As EventArgs) Handles dt.Tick
    ' Do Stuff here.
End Sub

*从这里将代码转换为 VB ,虽然我没有测试过它..它可能对你有用..

于 2012-11-02T14:20:49.250 回答
0

也许我只是不了解环境,因为我从未在 .Net 中为手机编程过,但是呢:

System.Threading.Thread.Sleep(2000)

希望这可以帮助

于 2012-11-02T13:53:41.883 回答