So I want to be able to display a message on a label without clicking the label.
public void servicestatus_Click_1(object sender, EventArgs e)
{
var mavbridgeservice = new System.ServiceProcess.ServiceController("MavBridge");
if (mavbridgeservice.Status == ServiceControllerStatus.Running)
{
servicestatus.Text = ("The service is running!");
}
else
{
servicestatus.Text = "The service is stopped!";
}
}
I tied to put (null, null) in the (object sender, EventArgs e), but that gave errors, which I don’t know why. My code inside there didn’t have any correlation with any clicking.
You obviously wish to display the status of the server.
But you don’t want o change it when the user asks for an update you want it to change automatically right?
You have two options.
EDIT: I see now that option#1 wont work, you will need the timer option below. I removed Option #1
Option #2
If it is changed outside your Program, then you could add a timer that asks every second or two seconds depending on how fast you wish to update your users, and in that time add your code to set the label
Then in your main form constructor, under the InitializeComponent(); line add this
in the timer.Tick event run your code to determine the status(what is currently in the click event of your label)