コード例 #1
0
        // running in Indexing or UI thread
        public void RunSearch(BackgroundSearcherParams searcherParams)
        {
            if (searcherParams.Path == null)
            {
                lock (this.BackgroundSearchers)
                {
                    foreach (var sear in this.BackgroundSearchers)
                    {
                        sear.CancelAsync();
                    }
                    this.BackgroundSearchers.Clear();
                }
            }
            var searcher = new BackgroundSearcher();

            searcher.RunWorkerCompleted += this.BackgroundSearcherWorkCompleted;
            if (searcherParams.Path != null)
            {
                searcher.RunWorkerSync(searcherParams);
            }
            else
            {
                searcher.RunWorkerAsync(searcherParams);
                lock (this.BackgroundSearchers)
                {
                    this.BackgroundSearchers.Add(searcher);
                }
            }
        }
コード例 #2
0
        private void StartStopSearchButton_Click(object sender, EventArgs e)
        {
            PushToSettings();

            if (SearchSettings.BadSettings())
            {
                MessageBox.Show("Ошибка! \nНужно задать корневую директорию и хотя бы один фильтр, и их длина должна быть не больше 50 символов.");
                return;
            }

            SearchStarted = !SearchStarted;

            if (SearchStarted)
            {
                DisableConfig();
                PauseResumeSearchButton.Enabled = true;
                StartStopSearchButton.Text      = "Stop";
                BackgroundSearcher.RunWorkerAsync();
                SearchTimer.Start();
            }
            else
            {
                BackgroundSearcher.CancelAsync();
                SearchPaused = false;
                EnableConfig();
                PauseResumeSearchButton.Text    = "Pause";
                PauseResumeSearchButton.Enabled = false;
                SearchTimer.Stop();
            }
        }