Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / Windows Forms / WinForm General / July 2006

Tip: Looking for answers? Try searching our database.

ToolStripProgressBar and InvokeRequired - again

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
daniel.wojciechowski@gmail.com - 05 Jul 2006 13:47 GMT
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
Jared Parsons [MSFT] - 05 Jul 2006 19:00 GMT
Hello daniel.wojciechowski@gmail.com,

> 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]
jaredpar@online.microsoft.com
All opinions are my own. All content is provided "AS IS" with no warranties,
and confers no rights
William Sullivan - 05 Jul 2006 21:23 GMT
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 daniel.wojciechowski@gmail.com,
>
[quoted text clipped - 13 lines]
> All opinions are my own. All content is provided "AS IS" with no warranties,
> and confers no rights.
Jared Parsons [MSFT] - 05 Jul 2006 21:59 GMT
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.

--
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.
daniel.wojciechowski@gmail.com - 07 Jul 2006 10:42 GMT
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.
daniel.wojciechowski@gmail.com - 07 Jul 2006 10:53 GMT
Jared wrote:
> Hello daniel.wojciechowski@gmail.com,
>
> 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
daniel.wojciechowski@gmail.com - 07 Jul 2006 11:09 GMT
daniel.wojciechow...@gmail.com wrote:
> Jared wrote:
> >
> > You will need to use the Invoke() method for cross thread access for all
> > objects in System.Windows.Forms.

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

Daniel

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.