ToolStripProgressBar and InvokeRequired - again

  • Thread starter daniel.wojciechowski
  • Start date
D

daniel.wojciechowski

Hello
Is manipulation on ToolStripProgressBar allowed in cross-thread way? Or
should I use this.Invoke()?

I'm using Dot Net since yesterday. Sorry, if this question doesn't have
sense.

Thanks,
Daniel
 
J

Jared Parsons [MSFT]

Hello (e-mail address removed),
Hello
Is manipulation on ToolStripProgressBar allowed in cross-thread way?
Or
should I use this.Invoke()?
I'm using Dot Net since yesterday. Sorry, if this question doesn't
have sense.

You will need to use the Invoke() method for cross thread access for all
objects in System.Windows.Forms.
 
G

Guest

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 Parsons said:
Hello (e-mail address removed),
Hello
Is manipulation on ToolStripProgressBar allowed in cross-thread way?
Or
should I use this.Invoke()?
I'm using Dot Net since yesterday. Sorry, if this question doesn't
have sense.

You will need to use the Invoke() method for cross thread access for all
objects in System.Windows.Forms.

--
Jared Parsons [MSFT]
(e-mail address removed)
All opinions are my own. All content is provided "AS IS" with no warranties,
and confers no rights.
 
J

Jared Parsons [MSFT]

Hello William,
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(...))?

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.
 
D

daniel.wojciechowski

Hello William,
Hello Jared,
and Hello everybody,
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(...))?
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 :)
 
D

daniel.wojciechowski

Jared said:
Hello (e-mail address removed),

You will need to use the Invoke() method for cross thread access for all
objects in System.Windows.Forms.

"All object"? All [Control] object? All [Component] object?
If "All object" than also should I call Invoke() for changing "String
frame1.someText"?

Daniel
 
D

daniel.wojciechowski

Ohhh "System.Windows.Forms" - name space! Now i got it. Previously i
thought about System.Windows.Form and all members of Form. Sorry.

Daniel
 
J

Jared Parsons [MSFT]

Hello (e-mail address removed),
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
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()?

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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top