RE: Question on Control.InvokeRequired and Cross UI Thread call? by newsgroup01
newsgroup01
Thu Oct 26 09:31:03 CDT 2006
> From my understanding you only get this exception if you try to get the
> controls handle and in your case it appears your are not trying to do that.
Sorry not true. If you try to do this.textBox1.Text = "abce";
It will generate the exception.
> There is also a property on controls called CheckForIllegalCrossThreadCalls.
Yes, this is on when running in debugger. It is false if running outside.
I set it to true prior the Application.Run() to ensure I get this exception
always. Good for beta and testing.
> If you set this property to false you will not get this exception even if
> you access the Handle property
>
> "Leon" wrote:
>
> > Hi,
> >
> > From MSDN documentation, it implies that any cross ui thread calls will
> > result in InvalidOperationException when one tries to access a UI object from
> > a non-creation thread.
> >
> > I have a situation where someone is executing some code in a thread pool
> > (Threading.IsThreadPoolThread is true and so if Form.InvokeRequired is true)
> > and yet when it calls
> >
> > // this.mainTabControl.InvokeRequired is true
> > TabControl tc = this.mainTabControl.TabPages[i];
> >
> > it does not throw the InvalidOperationException, why? Is this because it is
> > not actually accessing the UI part of the control? If is like going through
> > its internal list?
> >
> > Thanks.
> >
> > Leon
> >