0

BackgroundWorkerを更新すると思われる を実行していますUserControl。プロパティを確認した後、呼び出しを試みましたInvokeRequired

private void bgwHighlightText_DoWork(object sender, DoWorkEventArgs e)
{
   tmpRich.SelectedRtf = myRtf;
   if (_ucResultRich.InvokeRequired && _ucResultRich.rchResult.InvokeRequired)
     _ucResultRich.Invoke(new Action(() => _ucResultRich.rchResult.Rtf = tmpRich.Rtf)); // Debug pointer stops here

   //Rest of the code
}

RichTextBoxまた、内部をUserControl直接呼び出そうとしました:

_ucResultRich.rchResult.Invoke(new Action(() => _ucResultRich.rchResult.Rtf = tmpRich.Rtf));

しかし、コードをデバッグすると、残りのコードの実行がエラーなしで停止するだけです。

_ucResultRich.InvokeRequired_ucResultRich.rchResult.InvokeRequiredreturnの両方true

ここで何か間違ったことをしていますか?

アップデート

Invokeパーツを挿入するtry catchと、例外メッセージから次のエラーが表示されます。

Cross-thread operation not valid: Control '' accessed from a thread 
      other than the thread it was created on.

コントロールを決定できないからですか?のように表示されControl ''ます。

4

1 に答える 1