private void Button_ListFilesFromFolder_Click(object sender, RoutedEventArgs e) { switch (ComboBox_ListToShow.SelectedIndex) { case 0: ListView1.ItemsSource = IO.ListFileNamesFromFolder(Var.LocDirInput, "*.csv"); break; case 1: Ftp ftp1 = new Ftp(Var.FtpDirInput, Var.FtpUsername1, Var.FtpPassword1); ListView1.ItemsSource = ftp1.DirectoryListSimple(""); break; case 2: ListView1.ItemsSource = IO.ListFileNamesFromFolder(Var.LocDirOperation, "*.csv"); break; case 3: Ftp ftp3 = new Ftp(Var.FtpDirOperation, Var.FtpUsername1, Var.FtpPassword1); ListView1.ItemsSource = ftp3.DirectoryListSimple(""); break; case 4: ListView1.ItemsSource = IO.ListFileNamesFromFolder(Var.LocDirScales, "*.csv"); break; case 5: Ftp ftp5 = new Ftp(Var.FtpDirScales, Var.FtpUsername1, Var.FtpPassword1); ListView1.ItemsSource = ftp5.DirectoryListSimple(""); break; default: ListView1.ItemsSource = null; break; } }
private async void LoadFtp(string ftpDir, string locDir) { // Cancellation token CancellationTokenSource cts = new CancellationTokenSource(); // The Progress<T> constructor captures our UI context, // so the lambda will be run on the UI thread. var progress1 = new Progress <int>(percent1 => { Var.TaskProgress1 = percent1; }); var progressIndex = new Progress <int>(i => { ListView1.SelectedIndex = i; }); var progress2 = new Progress <int>(percent2 => { Var.TaskProgress2 = percent2; }); /* Create Object Instance */ Ftp ftpClient = new Ftp(ftpDir, Var.FtpUsername1, Var.FtpPassword1); /* Get Contents of a Directory (Names Only) */ IEnumerable <string> filesToLoad = ftpClient.DirectoryListSimple("").Except(IO.ListFileNamesFromFolder(locDir, "*.csv")).Take(Var.MaxFilesCount); await Task.Run(() => Var.ListView1Content = filesToLoad); // DoProcessing is run on the thread pool. await Task.Run(() => Ftp.LoadFtpFiles(filesToLoad, ftpDir, locDir, progress1, progress2, progressIndex)); Var.TaskProgress1 = 0; Var.TaskProgress2 = 0; }