im using a textbox and need to replace text in the textbox. the problem is that i need to replace 718 different items. I would like to put each replace into its own thread to quicken the process but when i do, it never replaces.
i have tried similar to the following
foreach (Match m in matchCollection)
{
ReplaceClass r = new ReplaceClass(TextBox,m,ReplaceText)
Thread th = new Thread(new ThreadStart(r.Replace))
th.start()
}
As Dyppl wrote in a comment you can access a form only from the thread in wich it was declared and it’s running.
I think that if you want to speed up the process don’t replace the text in the text box but just copy the text in a temporary string , modify it (replace the matches ) and then overwrite the text in the form.
So
Edit:
As the Anthony Pegram says , it’s not good to manipulate a string in such way inside a loop because the string gets created every time , but i don’t know what your replace function does. A better way could be
Or you can also use the functions to search and replace of regular expressions. Just don’t replace over the textbox because each time you make a replacement the control has to be drawn again.