Universal Windows Platform (UWP)
A Microsoft platform for building and publishing apps for Windows desktop devices.
2,971 questions
This browser is no longer supported.
Upgrade to Microsoft Edge to take advantage of the latest features, security updates, and technical support.
What is the code for a timer in UWP Visual Basic ?
I am having issues implementing the information at https://learn.microsoft.com/en-us/windows/uwp/threading-async/use-a-timer-to-submit-a-work-item
I only need to launch the timer at a certain point of my app and run a procedure when the timer reaches a given elapsed time.
Thanks.
Hi, try following MVVM demo:
XAML:
<Page
x:Class="UWP10App1VB.Page18"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="using:UWP10App1VB.UwpApp18"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
mc:Ignorable="d"
Background="{ThemeResource ApplicationPageBackgroundThemeBrush}">
<Page.DataContext>
<local:ViewModel/>
</Page.DataContext>
<StackPanel>
<Button Content="Start Timer" Command="{Binding Cmd}"/>
<TextBlock Text="{Binding Info}"/>
</StackPanel>
</Page>
ViewModel:
Namespace UwpApp18
Public Class ViewModel
Implements INotifyPropertyChanged
Private _info As String
Public Property Info As String
Get
Return Me._info
End Get
Set(value As String)
Me._info = value
OnPropertyChanged()
End Set
End Property
Public Property Cmd As ICommand = New RelayCommand(AddressOf CmdExec)
Private Sub CmdExec(obj As Object)
Dim sc = SynchronizationContext.Current
Info = "Timer will be startet"
Dim DelayTimer = ThreadPoolTimer.CreateTimer(Sub(source)
' do work
sc.Post(New SendOrPostCallback(Sub(state)
Info = "Timer ended"
End Sub), Nothing)
End Sub, TimeSpan.FromMinutes(1))
End Sub
Public Event PropertyChanged As PropertyChangedEventHandler Implements INotifyPropertyChanged.PropertyChanged
Friend Sub OnPropertyChanged(<CallerMemberName> Optional propName As String = "")
RaiseEvent PropertyChanged(Me, New PropertyChangedEventArgs(propName))
End Sub
End Class
End Namespace