Morgan Green Morgan Green - 13 days ago 6
C# Question

Run function until successful

I have an installation that runs post checks. What I'm looking to do is call the Function

private void ApacheTest()
{
if(!File.Exists(HTTPD_PATH))
{
amountdl.Text = "Apache Not Found! Installation Corrupt!";
}
else
{
StartApacheServer();
}
if(ApacheRunning() == false)
{
amountdl.Text = "Apache Is Starting";
}
else
{
amountdl.Text = "Apache Started";
}
}


What I want to happen is is until
ApacheRunning() == true
I want it to keep running this function. Is this something possible in C#?

Answer

Try:

private void ApacheTest()
{
    if(!File.Exists(HTTPD_PATH))
    {
        amountdl.Text = "Apache Not Found! Installation Corrupt!";
    }
    else
    {
        StartApacheServer();
    }

    amountdl.Text = "Apache Is Starting";
    while(ApacheRunning() == false)
    {
       Task.Delay(1000);
    }

    amountdl.Text = "Apache Started";        
}

Here I used Task.Delay(1000) to check state of server each seconds.

Comments