public class UpdateChecker { public static event EventHandler completeCheck;
private static bool isChecking = false;
private static WebClient wc;
public static void doUpdateCheck() { if (isChecking) return;
isChecking = true ;
wc = new WebClient();
wc.DownloadStringCompleted += new DownloadStringCompletedEventHandler(wc_DownloadStringCompleted);
wc.DownloadStringAsync(new Uri("https://files.cnblogs.com/files/wgscd/appupdate.xml"));
} private static void wc_DownloadStringCompleted(object sender, DownloadStringCompletedEventArgs e)
{
try
{
// MessageBox.Show(""+e.Result ,"update",MessageBoxButton.YesNo);
XmlDocument doc = new XmlDocument();
doc.LoadXml("" + e.Result);
string localVar="3.8";//test
string serverVer = doc.SelectSingleNode("app").Attributes["version"].Value;
string serverDate = doc.SelectSingleNode("app").Attributes["update_date"].Value;
string tip = doc.SelectSingleNode("app/tip").InnerText;
if (localVar.CompareTo (serverVer)<0) {
MessageBox.Show("the new version: " + serverVer + "\r\n " + tip + " \r\n update?\r\n", "update", MessageBoxButton.YesNo);
}
if (completeCheck != null) { completeCheck(sender, e); }
isChecking = false;
}
catch { }
wc.DownloadStringCompleted -= new DownloadStringCompletedEventHandler(wc_DownloadStringCompleted); } }