none
InvokeRequired not available on progress bar control

    Question

  • I am running C# Espress 2008 and .NET framework 3.5.
    I have a tiny Windows Application in which I want to update a progress bar from a thread that doesn't own it, so coded

    if (this.ProgressBar.InvokeRequired)

    but it won't compile because my progress bar doesn't have an InvokeRequired property.

    All the explanations and example code I've seen of how to do this make good sense, but only if you have an InvokeRequired property to test.

    Any idea why I don't have InvokeRequired?

    Thanks
    Rob
    Friday, May 16, 2008 12:27 PM

Answers

  • A second colleague tells me 1. that my original app was a WPF app and 2. that WPF does the thread handling for you, so all I have to do is find out how to drive it properly.

    I did create a Windows Forms Application and copied my old code into it.  After massaging it to suit the new application type, I found that my progress bar did have all the Invoke methods, etc, so that confirms that the original problem was an inheritance issue.
    Monday, May 19, 2008 12:32 PM

All replies

  • Hi Rob,

     

    You can use InvokeRequired method of owner of your ProgressBar control as well as use Invoke method of owner. Owner (form or control) of your progress bar will always run in the same thread as progress bar.

     

    Friday, May 16, 2008 12:42 PM
  • Thank you for responding Vitaliy, but sadly, the form doesn't have an InvokeRequired either.  I changed my code to

    if (this.InvokeRequired)

    and the compiler generated this error message:
    Error    2    'BulkLoaderTest.Window1' does not contain a definition for 'InvokeRequired' and no extension method 'InvokeRequired' accepting a first argument of type 'BulkLoaderTest.Window1' could be found (are you missing a using directive or an assembly reference?)   

    Thanks
    Rob

    Friday, May 16, 2008 12:57 PM
  • Pretty strange...

     

    InvokeRequired is defined in ISynchronizeInvoke interface. This interface is implemented by System.Windows.Forms.Control and Form is inherited from this control.

     

    Probable Express edition C# compiler is limited and you have to cast to this interface manually in your code...

    Friday, May 16, 2008 1:27 PM
  • Sorry to be so demanding but could you explain what you mean by 'cast to this interface manually'?  Although I've been programming for years, I'm new to c#.

    Thanks
    Rob
    PS I'm about to go home for the weekend, so may stop responding suddenly.  I'll check back on Monday.
    Friday, May 16, 2008 1:47 PM
  •  

    Here is sample:

     

    if (((ISynchronizeInvoke)this.ProgressBar).InvokeRequired)

    Friday, May 16, 2008 1:58 PM
  • Sadly, I get namespace name ISynchronizeInvoke could not be found.

    And I really am going to have to go home now.  Thank you very much for your help so far, Vitaliy.

    Rob
    Friday, May 16, 2008 2:05 PM
  • Hi Vitaliy

    I think I have found out what is causing my problem.  A colleague pointed out that my application is a Windows application, not a Forms application.  As a result, the progress bar doesn't inherit anything about Invoke.  I think I made it a Windows application without understanding what I was doing (still don't, actually!).

    So when I get a chance (c# development is not my proper job yet) I'll create a new Forms app and copy my existing code into it.  It's very small, so hopefully it'll be straightfoward to make it go.

    Thanks for your help and I'll try to remember to post an update later today.

    Rob
    Monday, May 19, 2008 9:48 AM
  • A second colleague tells me 1. that my original app was a WPF app and 2. that WPF does the thread handling for you, so all I have to do is find out how to drive it properly.

    I did create a Windows Forms Application and copied my old code into it.  After massaging it to suit the new application type, I found that my progress bar did have all the Invoke methods, etc, so that confirms that the original problem was an inheritance issue.
    Monday, May 19, 2008 12:32 PM