At the moment, I have the following code:
Public tmr() As DispatcherTimer
Public Sub CreateTimer(ByVal timernumber As Integer)
Dim main As New MainWindow
Dim tmr(timernumber) As DispatcherTimer
tmr(timernumber - 1).Stop()
tmr(timernumber).Start()
tmr(timernumber).Interval = New TimeSpan(0, 0, 0, 0, 50)
AddHandler tmr(timernumber).Tick, AddressOf main.tmr_tick
End Sub
Public Sub CreateFirstTimer(ByVal timernumber As Integer)
Dim main As New MainWindow
Dim tmr(timernumber) As DispatcherTimer
tmr(timernumber).Interval = New TimeSpan(0, 0, 0, 0, 50)
tmr(timernumber).Start()
AddHandler tmr(timernumber).Tick, AddressOf main.tmr_tick
End Sub
This is part of a slightly Object – Oriented application, and two subroutines feed this class with a variable ‘timernumber’. This all looks like it should work, however, when the application goes to use these subroutines, it crashes, as the Dim tmr(timernumber) As DispatcherTimer doesn’t have a “new” statement in it (As New DispatcherTimer). When I put a “New” in, VB complains about not being able to use the New keyword with an array.
So, I suppose how can I dynamically create dispatchertimers in WPF, all of which work? And perhaps “delete” the old ones on the way?
Thank you everyone!
Is
tmrdeclared somewhere else? If so you want to use: