Results 1 to 8 of 8

Thread: dispatchtimer to work in vb.net?

  1. #1

    Thread Starter
    Hyperactive Member
    Join Date
    May 2007
    Posts
    439

    dispatchtimer to work in vb.net?

    I cant get the dispatchtimer to work in vb.net.

    I want the MainGameLoop() code to run every 20MS after i click abutton but this doesnt do that.



    Dim dt As DispatcherTimer

    Private Sub mybutton_Click(ByVal sender As Object, ByVal e As System.Windows.RoutedEventArgs) Handles mybutton.Click
    dt = New DispatcherTimer
    dt.Interval = TimeSpan.FromMilliseconds(20)

    ' Dim MainGameLoop As EventHandler

    ' AddHandler dt.Tick, MainGameLoop
    MainGameLoop() 'just runs once

    End Sub



    Private Sub MainGameLoop()

  2. #2
    PowerPoster sparrow1's Avatar
    Join Date
    May 2005
    Location
    Globetrotter
    Posts
    2,820

    Re: dispatchtimer to work in vb.net?

    Hi,

    I think you forgot to start the timer:

    vb Code:
    1. dt.Enable = true

    Wkr,

    sparrow1
    Wkr,
    sparrow1

    If I helped you, don't forget to Rate my post. Thank you

    I'm using Visual Studio.Net 2003 and
    2005
    How to learn VB.Net Create setup with VB 2005 Drawing for beginners VB.Net Tutorials GDI+ Tutorials
    Video's for beginners

  3. #3

    Thread Starter
    Hyperactive Member
    Join Date
    May 2007
    Posts
    439

    Re: dispatchtimer to work in vb.net?

    Quote Originally Posted by sparrow1
    Hi,

    I think you forgot to start the timer:

    vb Code:
    1. dt.Enable = true

    Wkr,

    sparrow1
    dt.Enable = True 'error as it is read only

    i have to add handler somehow?

  4. #4
    PowerPoster sparrow1's Avatar
    Join Date
    May 2005
    Location
    Globetrotter
    Posts
    2,820

    Re: dispatchtimer to work in vb.net?

    Hi,

    Forgot one lettre try this:

    vb Code:
    1. dt.Enabled = true
    Wkr,
    sparrow1

    If I helped you, don't forget to Rate my post. Thank you

    I'm using Visual Studio.Net 2003 and
    2005
    How to learn VB.Net Create setup with VB 2005 Drawing for beginners VB.Net Tutorials GDI+ Tutorials
    Video's for beginners

  5. #5

    Thread Starter
    Hyperactive Member
    Join Date
    May 2007
    Posts
    439

    Re: dispatchtimer to work in vb.net?

    forget this as there is no .Enabled property but just this and it is Read Only.

    dt.IsEnabled = True 'error as read only

  6. #6
    PowerPoster sparrow1's Avatar
    Join Date
    May 2005
    Location
    Globetrotter
    Posts
    2,820

    Re: dispatchtimer to work in vb.net?

    Hi,

    Try this:

    vb Code:
    1. dt.Start()

    Hope it helps this time,

    sparrow1
    Wkr,
    sparrow1

    If I helped you, don't forget to Rate my post. Thank you

    I'm using Visual Studio.Net 2003 and
    2005
    How to learn VB.Net Create setup with VB 2005 Drawing for beginners VB.Net Tutorials GDI+ Tutorials
    Video's for beginners

  7. #7

    Thread Starter
    Hyperactive Member
    Join Date
    May 2007
    Posts
    439

    Re: dispatchtimer to work in vb.net?

    NO it just runs the code once .
    The timer is not running every interval set.
    I am not adding a timer with an event properly as shown below as i dont know how to do.


    Dim dt As DispatcherTimer

    Private Sub mybutton_Click(ByVal sender As Object, ByVal e As System.Windows.RoutedEventArgs) Handles mybutton.Click
    dt = New DispatcherTimer
    dt.Interval = TimeSpan.FromMilliseconds(20)

    ' Dim MainGameLoop As EventHandler

    ' AddHandler dt.Tick, MainGameLoop
    dt.start()
    MainGameLoop() 'just runs once

    End Sub

  8. #8
    Powered By Medtronic dbasnett's Avatar
    Join Date
    Dec 2007
    Location
    Jefferson City, MO
    Posts
    9,897

    Re: dispatchtimer to work in vb.net?

    Code:
    Dim dt As DispatcherTimer
    
    Private Sub mybutton_Click(ByVal sender As Object, ByVal e As System.Windows.RoutedEventArgs) Handles mybutton.Click
    dt = New DispatcherTimer '<<<------- Do you want a new timer every click??  If not move this.
    dt.Interval = TimeSpan.FromMilliseconds(20)
    AddHandler dt.Tick, addressof MainGameLoop
    dt.start()
    End Sub
    
    Private Sub MainGameLoop(ByVal sender As Object, ByVal e As EventArgs) 
    End Sub
    I don't have SPOT so ...
    My First Computer -- Documentation Link (RT?M) -- Using the Debugger -- Prime Number Sieve
    Counting Bits -- Subnet Calculator -- UI Guidelines -- >> SerialPort Answer <<

    "Those who use Application.DoEvents have no idea what it does and those who know what it does never use it." John Wein

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