X秒后触发事件

时间:2012-11-02 13:28:16

标签: vb.net windows-phone-7 timer visual-studio-2012 dispatchertimer

我正在开发一款适用于Windows手机的应用。我的问题是如何在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作为我的语言来开发它。任何帮助将不胜感激。

2 个答案:

答案 0 :(得分: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

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

答案 1 :(得分:0)

也许我只是不了解环境,因为我从来没有在.Net中为手机编程,但是怎么样:

System.Threading.Thread.Sleep(2000)

希望这有帮助