Results 1 to 3 of 3

Thread: Timer Elapsed Event?

  1. #1

    Thread Starter
    Member
    Join Date
    May 2011
    Posts
    52

    Timer Elapsed Event?

    So I can't seem to get the elapsed event for the timer to work as it won't run the code after the interval is complete. What am I doing wrong? The only other code besides the timer code is code to add a couple columns to a datagrid.
    Code:
    Imports System.Timers
    
    Class MainWindow
        Private WithEvents mainTimer As Timer
    
        Private Sub Window_Loaded(sender As System.Object, e As System.Windows.RoutedEventArgs) Handles MyBase.Loaded
            'add columns to datagrid
            Dim linkColumn As New DataGridTextColumn : Dim titleColumn As New DataGridTextColumn
            linkColumn.Header = "Links:" : titleColumn.Header = "Titles:"
            linkColumn.Width = DataGrid1.Width / 2 : titleColumn.Width = DataGrid1.Width / 2
            linkColumn.Binding = New Binding("Links") : titleColumn.Binding = New Binding("Titles")
            DataGrid1.Columns.Add(linkColumn) : DataGrid1.Columns.Add(titleColumn)
    
            mainTimer.Interval = 100 : mainTimer.Enabled = True
        End Sub
    
        Private Sub mainTimer_Tick(sender As System.Object, e As ElapsedEventArgs) Handles mainTimer.Elapsed
            MsgBox("wow")
        End Sub
    End Class

  2. #2
    PowerPoster
    Join Date
    Sep 2006
    Location
    Egypt
    Posts
    2,579

    Re: Timer Elapsed Event?

    The error i see is that you have declared mainTimer but you didn't create an instance!
    Try this
    Code:
            mainTimer = New Timer
            mainTimer.Interval = 1000
            mainTimer.Enabled = True



  3. #3

    Thread Starter
    Member
    Join Date
    May 2011
    Posts
    52

    Re: Timer Elapsed Event?

    *facepalm* Thanks for the help!

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width