I have created a WinForms application which uses BackgroundWorker. The methods in BackgroundWorer displays messages on a RichTextBox. The _TextChanged event handler scrolls to the end of the RichTextBox.
Now the problem is that, I get an
UnHandled COMException : 0x8001010D (RPC_E_CANTCALLOUT_ININPUTSYNCCALL)
when RichTextBox.ScrollToCaret() is called from the _TextChanged event handler. What could be the problem? How to solve this issue?
As you've mentioned in the comments, you're accessing RichTextBox directly from the backgroundworker.
Accessing UI controls from multiple threads is strictly forbidden. Only the UI thread should access the controls.
You fix this you need to marshal the execution of the code that manipulates the UI controls (the RichTextBox in this case) onto the main UI thread, the thread that owns the RichTextBox.
You can do this in your backgroundworker code like this:
Invoke(new Action(() =>
{
// code that manipulates the RichTextBox here
}));
User contributions licensed under CC BY-SA 3.0