/// <summary> /// Helper method that should be called from the main thread prior to starting the background dictionary loader /// </summary> /// <param name="postSave">True to save the dictionary after loading</param> private void PreDictionaryLoader(bool postSave) { Pb1.Value = 0; Pb1.Show(); LabelDictionaryStatus.Text = DICT_STATUS_LABEL_PROMPT + "Loading..."; LabelDictionaryStatus.Show(); MenuItemDictionary.Enabled = false; _saveWhenFinished = postSave; }
/// <summary> /// The method called when the dictionary loader finishes. /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void DictionaryLoader_RunWorkerCompleted(object sender, RunWorkerCompletedEventArgs e) { bool? result = e.Result as bool?; Exception error = e.Result as Exception; if (e.Error != null) { MessageBox.Show("An error occurred loading the dictionary:\n" + e.Error.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } else if (e.Cancelled) { //TODO: Handle user cancelled } else if (result != null && result.HasValue) { if (result.Value) { LabelDictionarySave.Text = DICT_LABEL_PROMPT + Tree.WordCount; BtnFindWords.Enabled = true; } else { MessageBox.Show("Error loading"); } } else if (error != null) { MessageBox.Show("An error occurred whilst loading the dictionary: " + error.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } Pb1.Hide(); LabelDictionaryStatus.Hide(); MenuItemDictionary.Enabled = true; if (!File.Exists(GetDictionaryPath()) && Tree.WordCount > 0) { PreDictionarySaver(null); } }