How to call a control method from another thread

后端 未结 2 392
别那么骄傲
别那么骄傲 2021-01-26 07:46

I want to call RichTextBox.Find() from another thread. How can I do that? The RichTextBox is located in a UserControl which I\'m using in

2条回答
  •  无人共我
    2021-01-26 08:46

    You need to decouple your code a bit from UI controls and do your business logic on external thread and update UI control on Dispatcher.BeginInvoke or Invoke.

    For example ,you can save the text that your Textbox has in a separate property and do Find on other thread ,once you are done post the UI highlight part on UI thread.

提交回复
热议问题