Пример #1
0
        /// <summary>
        /// Adds image files to library with user open-folder dialog; uses background worker to add the files
        /// and uses this thread to display the add operation's progress to user
        /// </summary>
        private void AddFolder()
        {
            // Create FolderBrowserDialog to browse folders
            WinForms.FolderBrowserDialog dialog = new WinForms.FolderBrowserDialog();

            // If user clicked OK (not Cancel) in folder dialog
            if (dialog.ShowDialog() == WinForms.DialogResult.OK)
            {
                // Create viewmodel (i.e. window) for the progress bar
                _addProgressViewModel = new AddFileProgressViewModel(this);

                // Create background worker that will add the files
                _worker = new BackgroundWorker
                {
                    WorkerReportsProgress      = true,
                    WorkerSupportsCancellation = true
                };
                _worker.DoWork             += AddFolderWork;
                _worker.ProgressChanged    += UpdateAddProgress;
                _worker.RunWorkerCompleted += AddComplete;

                // Run worker
                _worker.RunWorkerAsync(dialog);
            }
        }
Пример #2
0
        /// <summary>
        /// Adds image files to library with user open-file dialog; uses background worker to add the files
        /// and uses this thread to display the add operation's progress to user
        /// </summary>
        private void AddFiles()
        {
            // Create OpenFileDialog to browse files
            OpenFileDialog dialog = new OpenFileDialog
            {
                // Filter dialog to only show supported image types
                Filter = "Images|*.jpg; *.jpeg; *.png; *.gif; *.bmp; *.exif; *.tiff",

                // Set dialog to select multiple files
                Multiselect = true
            };

            // If user clicked OK (not Cancel) in file dialog
            if (dialog.ShowDialog() == true)
            {
                // Create AddFileProgressModel for the progress bar
                _addProgressViewModel = new AddFileProgressViewModel(this);

                // Create background worker that will add the files
                _worker = new BackgroundWorker
                {
                    WorkerReportsProgress      = true,
                    WorkerSupportsCancellation = true
                };
                _worker.DoWork             += AddFilesWork;
                _worker.ProgressChanged    += UpdateAddProgress;
                _worker.RunWorkerCompleted += AddComplete;

                // Run worker
                _worker.RunWorkerAsync(dialog);
            }
        }