For the beginners, working on thread might come across the error saying “Cross-thread operation not valid“. This type error comes normally when Windows control created in one thread and accessed in another.
Because the Windows control are not thread safe by default.
![ThreadCommunication ThreadCommunication](https://i0.wp.com/jitendrazaa.com/blog/wp-content/uploads/2010/12/ThreadCommunication.png?resize=352%2C137&ssl=1)
The best way to solve this kind of error is :
if (InvokeRequired) { this.Invoke(new MethodInvoker(delegate { //Your code here, like set text box content or get text box contents etc.. })); } else { // Your code here, like set text box content or get text box contents etc.. // SAME CODE AS ABOVE }
Leave a Reply