Exception in using control in Mainform

  • Thread starter Thread starter Gomez
  • Start date Start date
G

Gomez

When I call a method by remoting I get the following exception-
"Control 'conrolname' accessed from a thread other than the thread it was
created on"
Can someone advise how to cope with that provided that I must use this call
somehow?
Regards
Gomez
 
Gomez said:
When I call a method by remoting I get the following exception-
"Control 'conrolname' accessed from a thread other than the thread it was
created on"
Can someone advise how to cope with that provided that I must use this
call somehow?

You can transfer control from the remoting thread into the thread that
created the control by means of the method "Invoke" that all controls have.

For instance, if you are doing theControl.theProperty=theValue; in your
remoted method, you can replace it with this:

theControl.Invoke(new MethodInvoker(myMethod));
...
private void myMethod()
{
theControl.theProperty=theValue;
}

Of course, there are many ways to write the preceding, such as using an
anonymous method inside the call to Invoke instead of the separate myMethod.
This would let you 'capture' theValue instead of passing it around in a
member value as would be required by the previous code example.
 
When I call a method by remoting I get the following exception-
"Control 'conrolname' accessed from a thread other than the thread it was
created on"
Can someone advise how to cope with that provided that I must use this call
somehow?
Regards
Gomez

You have to use Control.Invoke to make sure that y ou modify the
control from the UI thread. If you do a search for "Control.Invoke" in
this NG you will find a lot of posts about this
 
Back
Top