BF2Statistics.HostsFileTestForm.VerifyDnsCache C# (CSharp) Method

VerifyDnsCache() protected method

This method ping's the gamepsy services and verifies that the HOSTS file redirects are working correctly
protected VerifyDnsCache ( ) : void
return void
        protected void VerifyDnsCache()
        {
            // Loop through each service
            for (int i = 0; i < Services.Length; i++)
            {
                // Quit on cancel
                if (TaskSource.IsCancellationRequested)
                    return;

                // Make sure this service exists in the hosts file
                if (i < 4 && Redirector.GamespyServerAddress == null || Redirector.StatsServerAddress == null)
                {
                    SetStatus(i, "Skipped", Resources.question_button, "Entry not found in HOSTS file. Assumed redirect was not desired by user");
                    continue;
                }

                // Prepare for next service
                SetStatus(i, "Checking, Please Wait...", Resources.loading);

                // Ping server to get the IP address in the dns cache
                try
                {
                    IPAddress HostsIp = (i == 4) ? Redirector.StatsServerAddress : Redirector.GamespyServerAddress;
                    DnsCacheResult Result = new DnsCacheResult(Services[i], HostsIp);

                    // Update Gamespy Redirector Cache
                    Redirector.DnsCacheReport.AddOrUpdate(Result);

                    // Throw bad result
                    if (Result.IsFaulted)
                    {
                        // No such hosts is known?
                        if (Result.Error.InnerException != null)
                            SetStatus(i, "Error Occured", Resources.error, Result.Error.InnerException.Message);
                        else
                            SetStatus(i, "Error Occured", Resources.error, Result.Error.Message);
                    }

                    // Check for cancel before setting a form value
                    if (TaskSource.IsCancellationRequested)
                        return;

                    // Verify correct address 
                    if (Result.GotExpectedResult)
                        SetStatus(i, HostsIp.ToString(), Resources.check);
                    else
                        SetStatus(i, Result.ResultAddresses[0].ToString(), Resources.warning, "Address expected: " + HostsIp.ToString());
                }
                catch
                {
                    // Check for cancel before setting a form value
                    if (TaskSource.IsCancellationRequested)
                        return;
                }
            }

            // Enable refresh btn
            if(IsHandleCreated)
                Invoke((Action)delegate { RefreshBtn.Enabled = true; });
        }