메소드/하위 내부에서 타이머를 사용할 수 없습니다. 타이머가 작동하는 유일한 방법은 주기적으로 이벤트를 발생시키는 것입니다.; 타이머의 경우 타이머를 "틱"할 때마다 발생하는 "Tick"이벤트라고합니다.
아마도 MainWindow_Loaded
메서드가 MainWindow
클래스의 Loaded
이벤트를 처리하는 이벤트를 이미 알고있을 것입니다.
당신이해야 할 일은 응용 프로그램에 타이머를 추가하고 Tick 이벤트를 처리하고 이벤트 핸들러가 현재 위치로 텍스트 상자를 업데이트하는 것입니다. 예를 들어
:
Public Class MainWindow
Private WithEvents timer As New System.Windows.Threading.DispatcherTimer()
Public Sub New()
' Initialize the timer.
timer.Interval = new TimeSpan(0, 0, 1); ' "tick" every 1 second
' other code that goes in the constructor
' ...
End Sub
Private Sub timer_Tick(sender As Object, e As EventArgs) Handles timer.Tick
' TODO: Add code to update textbox with current position
End Sub
Private Sub MainWindow_Loaded(sender As Object, e As RoutedEventArgs)
' Start the timer first.
timer.Start()
' Then start playing your music.
MyiSoundengine.Play2D("Music/001.mp3")
End Sub
' any other code that you need inside of your MainWindow class
' ...
End Class
참고 타이머 객체의 클래스 수준의 선언에 WithEvents
키워드의 사용. 따라서 이벤트 처리기에서 Handles
문만 사용하여 해당 이벤트를 쉽게 처리 할 수 있습니다. 그렇지 않으면 생성자 내부에서 AddHandler
을 사용하여 이벤트 처리기 메서드를 원하는 이벤트에 연결해야합니다.