/// <summary> /// Finish the work /// </summary> private void bw_RunWorkerCompleted(object sender, RunWorkerCompletedEventArgs e) { // The background process is complete. First we should hide the // modal Progress Form to unlock the UI. The we need to inspect our // response to see if an error occurred, a cancel was requested or // if we completed successfully. // Hide the Progress Form if (_fmProgress != null) { _fmProgress.Hide(); _fmProgress = null; } // Check to see if an error occurred in the // background process. if (e.Error != null) { MessageBox.Show(this, e.Error.Message); return; } // Check to see if the background process was canceled. if (e.Cancelled) { MessageBox.Show(this, "実行キャンセル"); return; } // Everything completed normally. // process the response using e.Result MessageBox.Show(this, "実行完了"); }
/// <summary> /// Run write excavation information and statistical information /// </summary> private void btnRun_Click(object sender, EventArgs e) { if (_mokkanFolder == "") { MessageBox.Show(this, "木簡保存場所を指定ください.", "木簡情報一括更新・登録", MessageBoxButtons.OK); btnInfoBrowser.Focus(); return; } if (ckbFileUpdate.Checked) { _startRIdSet = Int32.TryParse(txtKaishiRBangou.Text, out _startRId); if (_infoFile == "" && !_startRIdSet) { MessageBox.Show(this, "調査情報テーブルファイルまたは開始R番号を指定ください.", "木簡情報一括更新・登録", MessageBoxButtons.OK); btnInfoBrowser.Focus(); return; } // read excavation information if (_infoFile != "") { ReadExcavationInfo(); } // change mokkan's rid MkaDefine.SaveMokkanImageAsSaving = _startRIdSet; } if (ckbRegisterDb.Checked) { // reset database ResetDb(); MkaDefine.RegisterToDbAsSaving = true; } else { MkaDefine.RegisterToDbAsSaving = false; } _statWriter = new StreamWriter("統計情報テーブル.csv", false, Encoding.GetEncoding("shift_jis")); _statGlassWriter = new StreamWriter("統計情報_削りごと.csv", false, Encoding.GetEncoding("shift_jis")); List <string> _gridPaths = Directory.GetDirectories(_mokkanFolder).ToList(); _batPaths = new List <string>(); foreach (String _gridPath in _gridPaths) { _grid = Path.GetFileName(_gridPath); _batPaths.AddRange(Directory.GetDirectories(_gridPath).ToList()); } _batPaths.Sort(CompareBat); if (_batPaths.Count == 0) { MessageBox.Show(this, "バットファイルは一つも存在していません.", "木簡情報一括更新・登録", MessageBoxButtons.OK); return; } // Create a background thread BackgroundWorker bw = new BackgroundWorker(); bw.DoWork += new DoWorkEventHandler(bw_DoWork); bw.RunWorkerCompleted += new RunWorkerCompletedEventHandler(bw_RunWorkerCompleted); // Create a progress form on the UI thread _fmProgress = new MkaWndProgress(); _fmProgress.Text = "実行中"; // Kick off the Async thread bw.RunWorkerAsync(); // Lock up the UI with this modal progress form. _fmProgress.ShowDialog(this); _fmProgress = null; _statWriter.Close(); _statGlassWriter.Close(); }