Allowing access to controls from another thread

  • Thread starter Thread starter NickP
  • Start date Start date
N

NickP

Hi there,

This might sound like a stupid question but this whole exception being
thrown when accessing user controls from another thread is extremely over
the top!

Just looking at the index property of a listviewitem from another thread
throws an exception! Is there any way to allow these as invoking the host
thread to do the work is going to really slow things down unless I change
the architechture completely. Wouldn't it have made sense to have an option
to make the control invoke itself rather than raising an exception?? Maybe
I'm missing the point

I understand that there may be consequences, but surely cant we decide
that ourselves??

Nick.
 
NickP said:
Hi there,

This might sound like a stupid question but this whole exception
being thrown when accessing user controls from another thread is
extremely over the top!

Just looking at the index property of a listviewitem from another
thread throws an exception! Is there any way to allow these as
invoking the host thread to do the work is going to really slow
things down unless I change the architechture completely. Wouldn't
it have made sense to have an option to make the control invoke
itself rather than raising an exception?? Maybe I'm missing the
point

I understand that there may be consequences, but surely cant we
decide that ourselves??


No, because it's not supported by the OS. Where's the problem if you have to
use BeginInvoke to have the UI thread do something?


Armin
 
Hi Armin,

Of course the operating system supports it, the control itself can
handle calls from another thread, that's simple enough to do. I've just
come across a property of one control called...

CheckForIllegalCrossThreadCalls

The problem I have with invoking is that with the current architechture
of my control if I were to simply use this as necessary it would cause the
host thread to perform the tasks that the worker thread was designed to do.
I haven't had any problems as yet with this control being manipulated from
another thread. Indeed if this is the shape of things to come then I should
create a new control anyway, which I have just started, but it's still time.

Anyway, I'm going to carry on, and check this property out too to see if
it's in the control im trying to re-write. Thanks for your help!

nick.
 
NickP said:
Hi Armin,

Of course the operating system supports it, the control itself
can handle calls from another thread, that's simple enough to do.

It may work, but there's no guarantee. That's why I didn't mention
CheckForIllegalCrossThreadCalls because it's value is not True in vain.
I've just come across a property of one control called...

CheckForIllegalCrossThreadCalls

The problem I have with invoking is that with the current
architechture of my control if I were to simply use this as
necessary it would cause the host thread to perform the tasks that
the worker thread was designed to do.

It does not make much sense to put work in a separate thread if it's main
job is manipulating controls.


Armin
 
Back
Top