Reputation: 515
I am developing an app for windows phone. My question is how can I trigger an event after 2 seconds?
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
I am using Visual Basic as my language in developing this. Any help would be much appreciated.
Upvotes: 1
Views: 5147
Reputation: 3850
declare dispatcherTimer inside the class
Dim WithEvents dt As System.Windows.Threading.DispatcherTimer
then create instance of dispatcherTimer whereever you want, set time span
dt = New System.Windows.Threading.DispatcherTimer()
dt.Interval = New TimeSpan(0, 0, 0, 0, 500) '' 500 Milliseconds
dt.Start()
and here is your handler
Private Sub dt_Tick(ByVal sender As Object, ByVal e As EventArgs) Handles dt.Tick
' Do Stuff here.
End Sub
*converted code to VB from here, though I have not tested it..it may work for you..
Upvotes: 2
Reputation: 19574
Maybe I just don't know the environment because I have never programmed for phones in .Net, but what about:
System.Threading.Thread.Sleep(2000)
Hope this helps
Upvotes: 0