Quantcast
Channel: Windows Presentation Foundation (WPF) forum
Viewing all articles
Browse latest Browse all 18858

OpenFileDialog with Backgroundworker do work

$
0
0

I'm on WPF application and I'm using OpenFileDialog to load many images. At the same i'm calling many function to convert images based on selection of some checkBoxes. If i select 100 images it'll take approximately 1 minute to process, so I would like to handle it by 'BackGroundWorker _ doWork".

First I load the images to a temporary dir and apply some functions & then transfer images to another directory.

I don't know how can i handle this, please help me. Thank you.

	private void b35x5Files_Click(object sender, RoutedEventArgs e)
        {  bgw.RunWorkerAsync();

        }       

	   void bgw_DoWork(object sender, DoWorkEventArgs e)
        {
            var backgroundWorker = sender as BackgroundWorker;

            OpenFileDialog dialog = new OpenFileDialog();
            dialog.Filter = "Image files (*.jpg; *.jpeg; *.gif; *.tiff; *.png) | *.jpg; *.jpeg; *.gif; *.tiff; *.png";
            dialog.InitialDirectory = Environment.GetFolderPath(Environment.SpecialFolder.MyPictures);
            dialog.Title = "Images";
            dialog.Multiselect = true;
            if (dialog.ShowDialog() == System.Windows.Forms.DialogResult.OK)
            {
                int finalcountvalue = dialog.FileNames.Length + fileCount35x5;
                fileCount35x5 = dialog.FileNames.Length;
                foreach (string fileName in dialog.FileNames)//Copy files to a temp directory
                {
                    System.IO.File.Copy(fileName, tdestination_dir35x5 + @"\" + System.IO.Path.GetFileName(fileName), true);
                }


                fliptToVertical();// To change the image Orinetation

                if (c35x5ftimage.IsChecked == true)//CheckBox for AutoColorCorrection
                {
                    //MessageBox.Show("Hi, focker");

                }
                if (c35x5sepia.IsChecked == true)//CheckBox for Sepai Tone
                {
                    doSepia(destination_dir35x5);
                }
                if (c35x5grayscale.IsChecked == true)//CheckBox for GrayScale Tone
                {
                    doGrayScale(destination_dir35x5);
                }

                try // After finishing the above funciton move files to main directory
                {
                    foreach (string path in Directory.GetFiles(tdestination_dir35x5, "*.*",
                            SearchOption.TopDirectoryOnly))
                        File.Copy(path, path.Replace(tdestination_dir35x5, destination_dir35x5), true);
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.ToString());
                }

            }

        }

        void bgw_ProgressChanged(object sender, ProgressChangedEventArgs e)
        {
            pbProcessing.Value = e.ProgressPercentage;
        }

        void bgw_RunWorkerCompleted(object sender, RunWorkerCompletedEventArgs e)
        {
            pbProcessing.Value = 100;
            MessageBox.Show("Finisheed ", "Completed", MessageBoxButton.OK, MessageBoxImage.Information);
        }


Viewing all articles
Browse latest Browse all 18858

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>