> Just wondering if you know this... Is there any benefit to using
> this.Invoke (this referring to the containing form), or is it better
> to use control.Invoke (where control is whatever windows control you
> wish to manipulate, e.g., toolStripProgressBar.Invoke(...))?
Hello William,
Hello Jared,
and Hello everybody,
William wrote:
> Just wondering if you know this... Is there any benefit to using
> this.Invoke (this referring to the containing form), or is it better
> to use control.Invoke (where control is whatever windows control you
> wish to manipulate, e.g., toolStripProgressBar.Invoke(...))?
Jared wrote:
> It's better to call invoke on the object whose method you are calling. That
> way invoke will take you to the owning thread for that object.
I'm asking about calling Invoke() method for ToolStripProgressBar
manipulation because:
1. ToolStripProgressBar has no Invoke() method (should I call Invoke()
method on Frame?).
2. ToolStripProgressBar has no InvokeRequired property (so I thought
yesterday: "maybe it is not required to call Invoke?" ).
3. When I manipulate on some TextBox from another thread (without
calling Invoke()) I have an exception (debug configuration), BUT when I
manipulate on some ToolStripProgressBar or ToolStripStatusLabel from
another thread I have NO exception (also in debug).
Is the Invoke() method really required for manipulation on
ToolStripProgressBar from another thread? I know that it is needed for
TextBox, Button, etc. but what about ToolStripProgressBar and
ToolStripStatusLabel? If "Yes, it is required to call Invoke() also for
ToolStripProgressBar" than which Invoke()? Frame.Invoke()?
Sorry for my redundant questions - I just worry You understand my
English.
Thanks,
Daniel Wojciechowski
new needer of .Net knowledge :)
Jared Parsons [MSFT] - 07 Jul 2006 17:16 GMT
Hello daniel.wojciechowski@gmail.com,
> I'm asking about calling Invoke() method for ToolStripProgressBar
> manipulation because:
> 1. ToolStripProgressBar has no Invoke() method (should I call Invoke()
> method on Frame?).
Use the ProgressBar property on the ToolStripProgressBar. It inherits from
Control.
> 2. ToolStripProgressBar has no InvokeRequired property (so I thought
> yesterday: "maybe it is not required to call Invoke?" ).
I can definately see the logic there. There are a few classes in System.Windows.Forms
that can actually be accessed from multiple threads (very few). Unless you
know this though, assume they must be accessed from the thread they are created
on.
> 3. When I manipulate on some TextBox from another thread (without
> calling Invoke()) I have an exception (debug configuration), BUT when
[quoted text clipped - 6 lines]
> ToolStripStatusLabel? If "Yes, it is required to call Invoke() also
> for ToolStripProgressBar" than which Invoke()? Frame.Invoke()?
That's the biggest problem with Controls in WinForms needing to be accessed
from a single thread, it doesn't always produce an error. If you run the
code under the debugger in Vs 2005 it should produce an error almost every
time.
--
Jared Parsons [MSFT]
jaredpar@online.microsoft.com
All opinions are my own. All content is provided "AS IS" with no warranties,
and confers no rights.