"An object reference is required for the non-static field, method, or property" with toolstripstatus

38 views Asked by At

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?

0

There are 0 answers