Hi,
Cross-thread operation not valid - it is an error which normally appears when you try to access a control from a thread which did not create the control.
I'm not sure about the controls from your
checkLock
but it seems that
hide/show
methods try to modify some internal properties of object
s
(if you pay attention you can see that
s
is created in main thread, and then is accessed from the second thread. There are 2 solutions for this problem: 1) you can create your
checkLock
object in the same thread which calls the
checkLocks()
method, or 2) I would prefer using
BeginInvoke()
instead of creating a new thread:
public partial class client : Form
{
public static bool locks= false;
public client()
{
InitializeComponent();
checkLock cl = new checkLock();
BeginInvoke(new Action(()=>
{
cl.checkLocks();
}));
}
}
More about BeginInvoke -
http://msdn.microsoft.com/en-us/library/0b1bf3y3.aspx[
^]
Regards