Strange behavior with GTK::ProgressBar when updating outside the main thread.



Hi,

I had this strange problem with updating a progressbar with a callback from a thread.  My app starts with a Gtk::Window and when an event occurs a basic dialog box with two buttons is displayed.  The two buttons are "copy" and "close".  Inside the dialog I create a thread as shown below:

void g_FileCopyDialog::copyFrom()
{

 Glib::Thread *const thread = Glib::Thread::create(sigc::mem_fun(*file, &DirectFile::runCopyThread), true );

// it does not join....

}

This is run after the dialog is shown (.show()) through the Gtk:Window.  Basiclly "file" is a object that handles file copies. I also have a callback in g_FileCopyDialog:

// callback method
void g_FileCopyDialog::progressBarUpdate(unsigned int position, unsigned int max )
{

    gdk_threads_enter();
    m_pcopyprogressbar->set_fraction( (double) position/max );
    gdk_threads_leave();

    while( Gtk::Main::events_pending() )
        Gtk::Main::iteration();

}

With this setup the progress bar does not update.  But if I just press the "Close" button (which doesn't close the dialog.  I didnt setup the event yet) while the file is copying it will show the progress bar working.  This was driving me nuts, and I spent almost a day trying to get it working right.   Finally after trying all different things I decided to try updating the progress bar after I created the thread like this:

void g_FileCopyDialog::copyFrom()
{

 Glib::Thread *const thread = Glib::Thread::create(sigc::mem_fun(*file, &DirectFile::runCopyThread), true );

// it does not join....

 progressBarUpdate(1, 10000 ); // for some reason this makes the progress bar work like it should?????

}

If i just update once after the thread is kicked off it works like it should.  Can anyone enlighten me on why this occuring?


Thanks,

Steve



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]