'ping' automatically

hi,

I have a 'ping' program in .net 2003, and also a timer source code in .net 2003.

When the program is running, i want it to 'ping' the ip address automatically for every 2 minutes. But I don't know how to write it in code.

Can someone please help me

Thank You




Answer this question

'ping' automatically

  • akeiii

    Hi,

    You can use both, the timer as mintioned code or use windows schedule to run the code"or At command in the cmd.exe".




  • hattar

    Add a timer to your form.(say timer1)

    timer1.Interval = 120000;(120*1000 ms)

    and then subscribe to the Tick event of the timer where you call the ping code.

    Let me know if this is what you were looking for


  • Mark Schmidt-MSFT

    Can you explain a bit more

    I don't understand this part, 'and then subscribe to the Tick event of the timer where you call the ping code'

    thanks



  • Cyril Ike Payumo

    I tried running the program but nothing happened....


  • kyus

    hi,

    I don't understand what you mean. Can you explain further



  • Cryo75

    There's an example of Ping here:

    http://www.csharphelp.com/archives/archive6.html


  • BikashPatel

    Can someone help me check if i'm writing correctly
    Here is my code:


    Private Sub Timer1_Tick(ByVal sender As Object, ByVal e As System.EventArgs) Handles Timer1.Tick
    Dim objPingHost1 As New clsPing
    Dim lngPingReply1 As Long
    txtHost.Text = "152.226.142.3"

    objPingHost1.TimeOut = 5000
    objPingHost1.DataSize = 32
    objPingHost1.Host = Trim(Me.txtHost.Text)

    'Me.txtLog.Text = "Trying to ping" & Trim(Me.txtHost.Text) & "..."

    lngPingReply1 = objPingHost1.Ping()

    If (lngPingReply1 = objPingHost1.PING_ERROR) Then
    Me.txtLog.Text &= vbCrLf & "Camera2 OFF" '& objPingHost1.GetLastError.Description
    Else
    Me.txtLog.Text &= vbCrLf & "Camera2 ON" '& lngPingReply1 & "msec"
    End If
    End Sub

    Thanks yoU
    .


  • RoadHired

    the code seems in c# or c++, am i right
    I very sorry because I'm doing it in visual basic project, is it ok if i can have the above code in visual basic project Sorry to caused any trouble.


  • Sethimus

    That's cool, I will take a look.

    But i want it in visual basic.net 2003.

    thanks



  • Bruno.MMonteiro

    Drag and drop a timer to a Windows Form.Right click on it and click properties.In the property grid that comes up,set Interval to 12000.And click on the events tab(yellow in color)and double click on "Tick".You will see code such as

    private void timer1_Tick(object sender, System.EventArgs e)

    {

    //Write ping code here

    }

    This will execute the ping code once in 120 sec.


  • PtrosProgrammer

    Hi,

    I mean you have two ways to achieve this goal:
    1) by writing the code directly into your project (using timer control). The Guys already wrote this in the replies.
    2) by using windows schedule tool (in the control panel you'll find the tool "Scheduled Tasks"), use it from GUI or from Command line "at.exe".

    I hope this makes things clear!


  • 'ping' automatically