0

I'm trying to make my app start with a splash form to check for app version update then I want to terminate the splash screen if there is no update available and start my Main Form, And if there is an update the app will open the update link and terminate itself.

I'm checking for update like this

WebClient client = new WebClient();
        Stream stream = client.OpenRead("https://www.XXXXXXX");
        StreamReader reader = new StreamReader(stream);
        String content = reader.ReadToEnd();
        Console.WriteLine(content);
        if (content == "0.8")
        {
            // Correct Version, I want here to terminate the splash screen and start my main form
        }
        else
        {
            //Wrong version and needs an update, I want here to terminate the whole app.
        }

I tried different things but nothing seems to work as I exactly want can someone suggest a good way to do this ?

Ahmed Rizk
  • 11
  • 2

1 Answers1

0

You have some (IMHO) good advices here for the splash screen, in case: How to build splash screen in windows forms application? One thing I noted is that you should start a new Thread for this splash screen.

Next, you could place your code in the Form_Load section.

And finally, you can terminate the app with the instruction "Application.Exit()".

Here's an example, where I got a random txt file to simulate your version number. Put 574 instead of 575 to get your test true.

    private void Form1_Load(object sender, EventArgs e)
    {
        WebClient client = new WebClient();
        Stream stream = client.OpenRead("https://www.tdx.cat/bitstream/handle/10803/4928/mmgl12de12.pdf.txt;jsessionid=B93B27AF7FE4E9B8A98A31136880B626?sequence=13");
        StreamReader reader = new StreamReader(stream);
        String content = reader.ReadToEnd();
        Console.WriteLine(content);
        if (content.Substring(0, 3) == "575")
        {
            Application.Exit();
        }
    }
Fredy
  • 532
  • 3
  • 11