0

I get the error written in the title using toolstripstatus in the line serverstatus.Text = "Server Online " + totalTime + " ms"; and serverstatus.Text = "Server Offline"; every X second the stripstatus (serverstatus) will update the clients if the server is online or not.

public static double PingTimeAverage(string host)
    {
        long totalTime = 0;
        int timeout = 120;
        int echoNum = 1; //number of pings
        Ping pingSender = new Ping();

        try
        {
            PingReply reply = pingSender.Send(host, timeout);
            totalTime += reply.RoundtripTime;
            serverstatus.Text = "Server Online " + totalTime + " ms";
        }
        catch
        {
            serverstatus.Text = "Server Offline";
        }

        return totalTime / echoNum;

    }

and the timer tick

private void timer1_Tick(object sender, EventArgs e)
    {
        PingTimeAverage("any url/dns");
    }

What i should change?

Pietro Ariano
  • 113
  • 1
  • 2
  • 12
  • If you look at the related column on the right you could see that there are at least 5 question with your exact problem. None of them helps you? – Steve May 16 '16 at 18:27
  • Remove `static` You aren't doing anything with the return value. – LarsTech May 16 '16 at 18:27
  • What is `serverstatus`? If it's a class type then `Text` isn't static and you need an instance of it. – juharr May 16 '16 at 18:28
  • 1
    you are trying to use an instance field `serverstatus` in a static method. You can't do that. – Jonesopolis May 16 '16 at 18:30

0 Answers0