Использование webclient для загрузки файла с сервера индикатор выполнения не обновляет WPF
У меня есть простое приложение Auto Updater WPF я загружаю файлы с сервера но индикатор выполнения не обновляется проверьте приведенный ниже код
private void Button_Click_3(object sender, RoutedEventArgs e) { try { string LocalFilePath = System.IO.Directory.GetCurrentDirectory(); LocalFilePath += @"\FishBot.exe"; DateTime SysFileDate = File.GetLastWriteTime(LocalFilePath); string ftpURL = "ftp://www.intelligent-solutions.at/mrniceguy.exe"; FtpWebRequest request = (FtpWebRequest)WebRequest.Create(ftpURL); request.Method = WebRequestMethods.Ftp.GetDateTimestamp; //You could add Credentials, if needed request.Credentials = new NetworkCredential("philippftp2", "yijnobrgap"); FtpWebResponse response = (FtpWebResponse)request.GetResponse(); DateTime ServerFileDate = response.LastModified; if (SysFileDate & gt; ServerFileDate) { dashTab = false; fishTab = false; shovelTab = false; hpTab = false; ingameSettingsTab = false; DownloadUpdateTab = true; RaisePropertyChanged("DashTab"); RaisePropertyChanged("FishTab"); RaisePropertyChanged("ShovelTab"); RaisePropertyChanged("HPTab"); RaisePropertyChanged("IngameSettingTab"); RaisePropertyChanged("DownloadUpdateTab"); if (MessageBox.Show("New Update is Available, Click OK to download or Cancel to download it later", "Software Update Available", MessageBoxButton.OKCancel, MessageBoxImage.Information) == MessageBoxResult.OK) { DownloadUpdates(); ProgBar = true; RaisePropertyChanged("ProgBar"); } else { MessageBox.Show("No New Update is Available", "Software Update", MessageBoxButton.OK, MessageBoxImage.Information); } } } catch (WebException er) { String status = ((FtpWebResponse)er.Response).StatusDescription; } //WebClient webClient = new WebClient(); //webClient.DownloadFile("https://www.intelligent-solutions.at/patch/mrniceguy.exe", @"..\..\Updates\mrniceguy.exe"); //WebClient webClient = new WebClient(); //webClient.DownloadFileCompleted += new AsyncCompletedEventHandler(Completed); //webClient.DownloadProgressChanged += new DownloadProgressChangedEventHandler(ProgressChanged); // webClient.DownloadFileAsync(new Uri("https://www.dropbox.com/sh/5w1brwtfdxdqq3c/AABv9iM5q0jcTHo3rg0GWuGfa?dl=0"), @"c:\myfile.txt"); //MessageBox.Show("This is working"); } private void ProgressChanged(object sender, System.Net.DownloadProgressChangedEventArgs e) { ProgressBar.Value = e.ProgressPercentage; } private void Completed(object sender, AsyncCompletedEventArgs e) { MessageBox.Show("Download completed!"); } private void DownloadUpdates() { try { string ftpURL = "ftp://www.intelligent-solutions.at/"; FtpWebRequest request = (FtpWebRequest)WebRequest.Create(ftpURL); request.Method = WebRequestMethods.Ftp.ListDirectory; //You could add Credentials, if needed request.Credentials = new NetworkCredential("philippftp2", "yijnobrgap"); FtpWebResponse response = (FtpWebResponse)request.GetResponse(); DateTime dt = response.LastModified; Stream responseStream = response.GetResponseStream(); StreamReader reader = new StreamReader(responseStream); List & lt; string> directories = new List& lt; string> (); string line = reader.ReadLine(); while (!string.IsNullOrEmpty(line)) { directories.Add(line); line = reader.ReadLine(); } reader.Close(); //using (WebClient ftpClient = new WebClient()) //{ //ftpClient.Credentials = new System.Net.NetworkCredential("philippftp2", "yijnobrgap"); for (int i = 0; i & lt;= directories.Count - 1; i++) { if (directories[i].Contains(".")) { string path = "ftp://www.intelligent-solutions.at/" + directories[i].ToString(); //Uri ur = new Uri(path); string trnsfrpth = @"..\..\Updates\" + directories[i].ToString(); //ftpClient.DownloadFile(path, trnsfrpth);// (path, trnsfrpth); WebClient client = new WebClient(); client.DownloadProgressChanged += new DownloadProgressChangedEventHandler(ProgressChanged); client.DownloadFileCompleted += new AsyncCompletedEventHandler(Completed); client.DownloadFileAsync(new Uri(path), trnsfrpth); } else { // Directory.CreateDirectory(@"..\..\Updates\" + directories[i].ToString()); string ftpURL1 = "ftp://www.intelligent-solutions.at/" + directories[i].ToString(); request = (FtpWebRequest)WebRequest.Create(ftpURL1); request.Method = WebRequestMethods.Ftp.ListDirectory; //You could add Credentials, if needed request.Credentials = new NetworkCredential("hhhhh", "yijnobrgap"); response = (FtpWebResponse)request.GetResponse(); responseStream = response.GetResponseStream(); reader = new StreamReader(responseStream); List & lt; string> subdirectories = new List& lt; string> (); string line1 = reader.ReadLine(); while (!string.IsNullOrEmpty(line1)) { subdirectories.Add(line1); line1 = reader.ReadLine(); } reader.Close(); //using (WebClient ftpClient1 = new WebClient()) //{ // ftpClient1.Credentials = new System.Net.NetworkCredential("hhhh", "yijnobrgap"); for (int j = 0; j & lt;= subdirectories.Count - 1; j++) { if (subdirectories[j].Contains(".")) { try { string path = "ftp://www.intelligent-solutions.at/" + subdirectories[j].ToString(); Uri ur = new Uri(path); string trnsfrpth1 = @"..\..\Updates\" + subdirectories[j].ToString(); // File.SetAttributes(trnsfrpth1, FileAttributes.Normal); //ftpClient1.DownloadFile(path, trnsfrpth1); WebClient client = new WebClient(); client.DownloadProgressChanged += new DownloadProgressChangedEventHandler(ProgressChanged); client.DownloadFileCompleted += new AsyncCompletedEventHandler(Completed); client.DownloadFileAsync(new Uri(path), trnsfrpth1); } catch (WebException ex) { //String status = ((FtpWebResponse)exx.Response).StatusDescription; } } } //} } //ProgressBar.Value += Math.Ceiling(Convert.ToDouble(100 / directories.Count)); } // } } catch (WebException er) { String status = ((FtpWebResponse)er.Response).StatusDescription; } }
Что я уже пробовал:
Я пробовал использовать диспетчер, но не работал
[no name]
Мы не являемся сервисом "отлаживайте всю мою кодовую базу для меня". И ваша проблема, скорее всего, связана с попыткой сделать это изнутри события нажатия кнопки.
Malikdanish
Я поделился кодом для проверки