Gtk progress bar not updating

08-Nov-2015 05:54

If you've got more complicated updates to make, you could define a class to represent the UI state and pass it to the Report Progress method.

I don't have a large C# experience, but I think that the condition for exception should be: if (property Info == null

My GUI shouldn't care whether it needs to Invoke or not.

In other words: i don't think that it is the responsability of the GUI to perform the context-swithc.// in the main thread Windows Forms Synchronization Context m Ui Context = new Windows Forms Synchronization Context(); ... void Update GUI(object user Data) The stategy I propose in this answer reverses the communication roles of the threads. The only thing you didn't mention is how you properly dispose the timer once the Worker Thread is finished. "service GUI()" is a GUI level method within the form (this) that can change as many controls as you want. Parameters can be added to pass values, or (probably faster) use class scope variables with locks on them as required if there is any possibility of a clash between threads accessing them that could cause instability.

//in some non UI Thread //cause an update in the GUI thread. Instead of the worker thread pushing the data the UI thread polls for it. Since all you are wanting to do is display progress information from the worker thread then I think you will find that this solution is a great alternative to the marshaling solution. Note this can cause trouble when the application ends (i.e. Use Begin Invoke instead of Invoke if the non-GUI thread is time critical (keeping Brian Gideon's warning in mind). Now, it may be that you do something in the invoked code that will need to wait for the thread, which may not be immediately obvious if it's buried in some functions that you are calling, which itself may happen indirectly via event handlers.

I needed to be able to update its text from all threads.

The extra lines allow the window to automatically scroll to the newest lines.

My GUI shouldn't care whether it needs to Invoke or not.

In other words: i don't think that it is the responsability of the GUI to perform the context-swithc.// in the main thread Windows Forms Synchronization Context m Ui Context = new Windows Forms Synchronization Context(); ... void Update GUI(object user Data) The stategy I propose in this answer reverses the communication roles of the threads. The only thing you didn't mention is how you properly dispose the timer once the Worker Thread is finished. "service GUI()" is a GUI level method within the form (this) that can change as many controls as you want. Parameters can be added to pass values, or (probably faster) use class scope variables with locks on them as required if there is any possibility of a clash between threads accessing them that could cause instability.

//in some non UI Thread //cause an update in the GUI thread. Instead of the worker thread pushing the data the UI thread polls for it. Since all you are wanting to do is display progress information from the worker thread then I think you will find that this solution is a great alternative to the marshaling solution. Note this can cause trouble when the application ends (i.e. Use Begin Invoke instead of Invoke if the non-GUI thread is time critical (keeping Brian Gideon's warning in mind). Now, it may be that you do something in the invoked code that will need to wait for the thread, which may not be immediately obvious if it's buried in some functions that you are calling, which itself may happen indirectly via event handlers.

I needed to be able to update its text from all threads.

The extra lines allow the window to automatically scroll to the newest lines.

So you would be waiting for the thread, the thread would be waiting for you and you are deadlocked.