using the timer within a PING function

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • foster99
    New Member
    • Feb 2007
    • 11

    using the timer within a PING function

    I am new to VB.NET and I want to implement a timer function into a PING, below is the code which I am using to PING an ip address. I want the PING to be executed something like every 10 seconds, so that it updates a lablel.

    Any ideas how to do this?


    Dim ping As New System.Net.Netw orkInformation. Ping

    Dim options As New System.Net.Netw orkInformation. PingOptions
    options.DontFra gment = True

    Dim data As String = "aaaaaaaaaaaaaa aaaaaaaaaaaaaaa aaa"
    Dim buffer As Byte() = System.Text.Enc oding.ASCII.Get Bytes(data)

    Dim pingreply As System.Net.Netw orkInformation. PingReply
    Dim a() As Byte = {CInt(192), CInt(168), CInt(I0), CInt(5)}
    Dim IP As New System.Net.IPAd dress(a)

    pingreply = ping.Send(IP, 120, buffer, options)

    If pingreply.Statu s.ToString = "TimedOut" Then
  • foster99
    New Member
    • Feb 2007
    • 11

    #2
    Ah.. I didn't realise how simple a timer was, i had been playing with loops for ages.

    drag the timer function onto the form, create a subclass with whatever you want to execute in the timer inside it, put the name of the subclass behind the timer.

    Comment

    • Plater
      Recognized Expert Expert
      • Apr 2007
      • 7872

      #3
      Yeah hehe the timer objects are nice that way.
      Attach an event handler the Tick event of windows forms timer, set the interval and enable it and you are like done.

      Comment

      Working...