コード例 #1
0
ファイル: MainForm.cs プロジェクト: Henriet/Plarium_Threads
        private void StartClick(object sender, EventArgs e)
        {
            if (_directorySelected && _fileSelected)
            {
                StopThread();
                var selectedPath = FolderBrowser.SelectedPath;

                try
                {
                    int             countOfEntries  = 0;
                    EventWaitHandle eventWaitHandle = new AutoResetEvent(false);
                    var             helperThread    = new Thread(() => Helpers.SetMaximumForProgressBar(selectedPath, ref countOfEntries, eventWaitHandle));
                    helperThread.Start();
                    eventWaitHandle.WaitOne();

                    progressBar.Maximum = countOfEntries;
                    progressBar.Value   = 0;
                    var statusUpdater = new StatusUpdater(EnabledButtons)
                    {
                        Label = CurrentFileNameLabel, ProgressBar = progressBar
                    };
                    _scanner = new DirectoryScanner(selectedPath, treeView, saveFileDialog.FileName, statusUpdater, ErrorLogTextBox);

                    EnabledButtons(false);
                    _thread = new Thread(() => _scanner.Scan());
                    _thread.Start();
                }
                catch (ArgumentException)
                {
                    Helpers.WriteToLog(Resources.MainForm_DirectoryDoes_not_exsist, selectedPath);
                }
                catch (UnauthorizedAccessException)
                {
                    Helpers.WriteToLog(Resources.Access_denided_For, saveFileDialog.FileName);
                }
                catch (ThreadAbortException)
                { }
                catch (Exception ex)
                {
                    Helpers.WriteToLog(Resources.Error_message, ex.Message);
                }
            }
            else
            {
                MessageBox.Show(Resources.MainForm_StartClick_Please__select_file_and_folder, Resources.MainForm_Error,
                                MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }
コード例 #2
0
ファイル: MainForm.cs プロジェクト: Henriet/Plarium_Threads
        private void StartClick(object sender, EventArgs e)
        {
            if (_directorySelected && _fileSelected)
            {
                StopThread();
                var selectedPath = FolderBrowser.SelectedPath;

                try
                {
                    int countOfEntries = 0;
                    EventWaitHandle eventWaitHandle = new AutoResetEvent(false);
                    var helperThread = new Thread( () => Helpers.SetMaximumForProgressBar(selectedPath, ref countOfEntries, eventWaitHandle));
                    helperThread.Start();
                    eventWaitHandle.WaitOne();

                    progressBar.Maximum = countOfEntries;
                    progressBar.Value = 0;
                    var statusUpdater = new StatusUpdater(EnabledButtons){Label = CurrentFileNameLabel, ProgressBar = progressBar};
                    _scanner = new DirectoryScanner(selectedPath, treeView, saveFileDialog.FileName, statusUpdater, ErrorLogTextBox);

                    EnabledButtons(false);
                    _thread = new Thread(() => _scanner.Scan());
                    _thread.Start();
                }
                catch (ArgumentException)
                {
                    Helpers.WriteToLog(Resources.MainForm_DirectoryDoes_not_exsist, selectedPath);
                }
                catch (UnauthorizedAccessException)
                {
                    Helpers.WriteToLog(Resources.Access_denided_For, saveFileDialog.FileName);
                }
                catch (ThreadAbortException)
                { }
                catch (Exception ex)
                {
                    Helpers.WriteToLog(Resources.Error_message, ex.Message);
                }
            }
            else
            {
                MessageBox.Show(Resources.MainForm_StartClick_Please__select_file_and_folder, Resources.MainForm_Error,
                    MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }