Esempio n. 1
0
        private void textBoxPath_KeyDown(object sender, KeyEventArgs e)
        {
            if (e.KeyCode == Keys.Enter)
            {
                if (backgroundWorker.IsBusy)
                {
                    backgroundWorker.CancelAsync();
                }


                if (!String.IsNullOrEmpty(textBoxKeyword.Text))
                {
                    textBoxKeyword.Text = String.Empty;
                }

                listBoxFileList.Items.Clear();

                string dirPath = textBoxPath.Text;

                searchItems = new List <SearchItem>();

                //入力したパスがヘッダーファイルに存在しているか否か
                if (FileControl.IndexHeaderExists(indexHeaderFileData, dirPath))
                {
                    searchItems = indexFileData.Select(f => new SearchItem(f, Path.GetFileName(f), Path.GetDirectoryName(f).Replace(dirPath, ""))).ToList();
                    listBoxFileList.Items.AddRange(searchItems.ToArray());
                }
                else
                {
                    /*
                     * try{
                     *      //var fileList = Directory.GetFiles(dirPath, "*", SearchOption.AllDirectories);
                     *      var fileList = Directory.EnumerateFiles(dirPath, "*", SearchOption.AllDirectories);
                     *
                     *      searchItems = fileList.Select(f => new SearchItem(f, Path.GetFileName(f), Path.GetDirectoryName(f).Replace(dirPath, ""))).ToList();
                     *
                     *      listBoxFileList.Items.AddRange(searchItems.ToArray());
                     *
                     * }catch(System.Exception ex){
                     *
                     * }
                     */
                    //スレッド処理
                    //backgroundWorker.RunWorkerAsync();
                    backgroundWorker.RunWorkerAsync(dirPath);
                }
            }
            else if (e.KeyCode == Keys.Escape)
            {
                //MessageBox.Show("Escape");
                if (backgroundWorker.IsBusy)
                {
                    //MessageBox.Show("IsBusy");
                    backgroundWorker.CancelAsync();
                }
            }
        }