This is my first time with C# (So far I've been using it for about a week) and I have a few small issues and would like some pointers on tiding up my code. I have decided to make this section of my code multithreaded as before it was cause the program to near lockup while it ran this, however now it doesn't seem to run correctly at all.
The program should return saying a update is available however it does nothing but run the update Window twice and leave it there.
Here is the code and thanks in advance!
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Net;
using System.Threading;
namespace ProxySwitch
{
public partial class UpdateCheckWindow : Form
{
private ParameterizedThreadStart process;
public UpdateCheckWindow()
{
InitializeComponent();
}
private void UpdateCheckWindow_Resize(object sender, EventArgs e)
{
if (FormWindowState.Minimized == WindowState)
Hide();
}
private void UpdateCheckWindow_Load(object sender, EventArgs e)
{
Thread thread = new Thread(process);
thread.Start();
{
string VersionURL = "http://proxyswitch.co.uk/downloads/version.txt";
string result = null;
try
{
WebClient client = new WebClient();
result = client.DownloadString(VersionURL);
if (result.Contains("1"))
{
this.Close();
}
else
{
DialogResult UpdateResult = MessageBox.Show("A update is avaliable! Would you like to download the latest version?", "Update Avaliable!", MessageBoxButtons.YesNo, MessageBoxIcon.Asterisk);
if (UpdateResult == DialogResult.Yes)
{
System.Diagnostics.Process.Start("http://proxyswitch.co.uk/downloads/current/setup.exe");
this.Close();
}
else if (UpdateResult == DialogResult.No)
{
this.Close();
}
thread.Abort();
}
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
this.Close();
}
}
}
}
}