Home All Groups Group Topic Archive Search About

Allowing access to controls from another thread

Author
3 Feb 2006 2:17 PM
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.

Author
3 Feb 2006 3:38 PM
Armin Zingler
Show quote Hide quote
"NickP" <a@a.com> schrieb
> 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
Author
3 Feb 2006 4:37 PM
NickP
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.

Show quoteHide quote
"Armin Zingler" <az.nospam@freenet.de> wrote in message
news:e%23TP8jNKGHA.3272@tk2msftngp13.phx.gbl...
> "NickP" <a@a.com> schrieb
>> 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
Author
3 Feb 2006 5:25 PM
Armin Zingler
"NickP" <a@a.com> schrieb
> 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