Click here to Skip to main content
11,706,323 members (38,590 online)
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 14:45pm
Edited 27-Jun-11 15: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 197
1 Sergey Alexandrovich Kryukov 141
2 chainerlt 110
3 Mika Wendelius 80
4 ppolymorphe 71
0 OriginalGriff 9,070
1 Sergey Alexandrovich Kryukov 8,413
2 CPallini 5,189
3 Maciej Los 4,746
4 Mika Wendelius 3,676


Advertise | Privacy | Mobile
Web04 | 2.8.150819.1 | Last Updated 28 Jun 2011
Copyright © CodeProject, 1999-2015
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