public bool Download(string url, string file, int maxsize) { maxSize = maxsize; complete = false; error = false; string userAgent = (string)getreg.GetReg("HKEY_LOCAL_MACHINE\\SOFTWARE\\Citrix\\XenTools\\AutoUpdate", "UserAgent", Branding.GetString("BRANDING_userAgent")); client = new WebClient(); client.Headers.Add("User-Agent", userAgent); client.DownloadFileCompleted += new System.ComponentModel.AsyncCompletedEventHandler(DownloadCompleted); client.DownloadProgressChanged += new DownloadProgressChangedEventHandler(DownloadProgressChanged); client.DownloadFileAsync(new Uri(url), file); finished.WaitOne(900000); // 15 min return(complete && !error); }