Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: C# .NET Threading
I am using the following code to invoke the controls that are on the main UI thread in my application. The progress bar that I have in my Status Strip does not have a InvokeRequired, I need to somehow invoke the System.Windows.Forms.ToolStripProgressBar.
 
if (txtbox1.InvokeRequired)
{
    txtbox1.Invoke(new MethodInvoker(delegate { txtbox1.Text = string.Empty; }));
}
Posted 27-Jun-11 15:45pm
Edited 27-Jun-11 16:00pm
v2
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

Found it myself.
 
System.Windows.Forms.ToolStripProgressBarprgBarMain.GetCurrentParent().InvokeRequired
  Permalink  
Comments
Ramalinga Koushik at 28-Jun-11 0:56am
   
Good Call Sevak. My 5 too.
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 3

Sevak is right! You can always use parent's "InvokeRequired" if the control doesn't have one...
Alternately you can always check if the current thread is different from the main thread using PInvoke. If the threads are different you need to use Invoke else not. If you want I can share the code for that.
 
Hope that helps!
  Permalink  
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 2

This might be help you
 
this.BeginInvoke((ThreadStart)delegate()
 {
 
//UI change code goes here

});
 

Thanks
  Permalink  

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
0 OriginalGriff 240
1 Kamal Rocks 184
2 BillWoodruff 173
3 PIEBALDconsult 160
4 CPallini 155
0 OriginalGriff 5,695
1 DamithSL 4,506
2 Maciej Los 4,007
3 Kornfeld Eliyahu Peter 3,480
4 Sergey Alexandrovich Kryukov 3,180


Advertise | Privacy | Mobile
Web04 | 2.8.141216.1 | Last Updated 28 Jun 2011
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100