私はWinFormsアプリケーションに単語のスペルチェックを統合しようとしています。これまでのところ、相互運用性は後部に深刻な痛みをもたらしました。何時間も騒がれた後、私は最終的に実際のスペルチェックを行いました。予想通りCheckSpellingOnceだけでなく、基礎となるCheckSpellingメソッドは実行しますが、できるだけ早く私はGetSpellingSuggestionsを呼び出すように、アプリケーションはスロー...Word.Interop document closed
例外をスロー:「System.Runtime.InteropServices.COMException」をClosedCaptionに。 Spelling.dll追加情報:開いているドキュメントがないため、このコマンドは利用できません。
最初のアイデアは、そのそれぞれのラッパーからの根本的なCOMオブジェクトが切断が_wordAppので、それが作成されたものとは異なるスレッドから呼び出されているということでした。だから私はCheckSpelling()内から呼び出すことを試みましたが、残念なことに同じ結果が出ました。また、ドキュメントの開閉を試み、既存のアプリケーションインスタンスに新しいドキュメントを追加したり、_documentオブジェクト(_document.Application.GetSpellingSuggestions)からアプリケーションを取得したりしています。
これは何ですか?
追加情報:CheckSpellingOnceメソッドは、タイマイベントが発生すると(ユーザーがRichTextFieldでタイピングを停止すると)UIを呼び出すようになります - 複数回 - 同じ_wordAppオブジェクトを使用して、起動を避けようとしていますwinword.exeの複数のインスタンス
/// <summary>
/// Checks spelling with the text from the provided richtextbox in a new thread.
/// </summary>
public void CheckSpellingOnce()
{
_checkerThread = new Thread(new ThreadStart(CheckSpelling));
_checkerThread.Start();
}
/// <summary>
/// Checks the spelling of a richtextbox. Raises an event with the result when done.
/// </summary>
private void CheckSpelling()
{
if (_shouldBeChecking)
{
RaiseStatusChanged(SpellCheckStatus.Working);
Word.ProofreadingErrors toReturn = null;
UpdateStringFromTextBox();
if (!string.IsNullOrEmpty(_fromTextBox))
{
_document.Content.Delete();
_document.Words.First.InsertBefore(_fromTextBox);
_document.Content.LanguageID = _language; //Must be set specifically here for some f***d reason.
toReturn = _document.SpellingErrors;
RaiseSpellingChecked(toReturn);
RaiseStatusChanged(SpellCheckStatus.Idle);
}
}
}
public Word.SpellingSuggestions GetSpellingSuggestions(string word)
{
//throw new NotImplementedException();
Word.SpellingSuggestions toReturn = _wordApp.GetSpellingSuggestions(word, _missing, _missing, _missing, _missing, _missing, _missing);
return toReturn;
}
でもGetSpellingSuggestionsのこの実装で、それはそれ以上のもので、「toReturn」の行で不平を言い、そしてない...
public void GetSpellingSuggestions(string word)
{
//throw new NotImplementedException();
var _suggestionThread = new Thread(new ThreadStart(() =>
{
_document.Content.Delete();
_document.Words.First.InsertBefore(word);
_document.Content.LanguageID = _language;
Word.SpellingSuggestions toReturn = _wordApp.GetSpellingSuggestions(word, _missing, _missing, _missing, _missing, _missing, _missing);
Debug.Print(toReturn[0].ToString());
}));
_suggestionThread.Start();
}
あなたは[this](http://stackoverflow.com/questions/9718687/spell-checking-in-c-sharp-using-word-interop)SOの質問を見ましたか? –
@JeroenHeier私は - 喜びはありません。 –
エラーは_「開いている文書はありません」と表示されているため、スレッドの問題です。また、COMスレッドモデルは、複数のプロセスを扱うため、ここでは適用されません。 – MickyD