我正在运行一个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.InvokeRequired
返回true
。
我在这里做错了吗?
更新
我把Invoke
零件放进去try catch
,现在我可以从异常消息中得到以下错误:
Cross-thread operation not valid: Control '' accessed from a thread
other than the thread it was created on.
是因为它无法确定控制吗?因为它显示它像Control ''
。