Thread problem in Windows



Hi gtkmm developers and users..

First of all I like to say that I'm working with gtkmm since one year
and I'm very pleased with this great tool...

I'm doing a software that provides an user interface to communicate with
some hardware,
The software is finished but I want to add a very important feature.
Because this feature can have more solutions I will explain the process
a little more detailed, to obtain more advises and/or more opinions.

At some point in my software the user will click on a Button to write
his configuration options (that he chooses trough the GUI)to the
hardware, this action takes +- 1 second, but  during this waiting time
the user does not have a feed back of what is happening.
Actually the user sees the Button pushed down and when the write is done
he sees a message dialog telling that the action succeeded  or not.
If I launch a message dialog to with a simple message (after I would
upgrade it with a progress bar) like "Configuring", the message must be
closed/ hided before I call the routine. Right? but  then user dont sees
the message anymore  It's not what i want.

So I created a Thread using glib/thread
And made some unsuccessful tests...

///In the Button handle code..
void
MyClass::ButtonHandler()
{
        (....)
        Gtk::MessageDialog
writing("Writing...",false,Gtk::MESSAGE_INFO,Gtk::BUTTONS_NONE);

// I used Glib::thread_init() in the main.cpp before calling the main
Gtk::window
       
        Glib::Thread *const opcWriterThread = Glib::Thread::create(
             sigc::mem_fun(this, &MyClass::ThreadTest), true);
         opcWriterThread->join();
        writing.run();
        (....)
}

/////The thread Handler
void
MyClass::ThreadTest ()
{
    std::cout << "I will write" << std::endl;
           
    Sleep (10000);//to simulate the routine
    std::cout << "Phase one done" << std::endl;
 
  Sleep (10000);//to simulate the routine
    std::cout << "Phase two done" << std::endl;
            std::cout << "Finished writing" << std::endl;
}

My expected result was to see the the message dialog and the Couts at
the same time, but the dialog only appears after thread finishes (after
"Finished writing").

Ok, Is this the best solution, do you have a better Idea for this feature?
If this is the good way what is missing? Is it because I'm working on
Windows (Xp sp2).
Sorry of this big email...


Filipe Apóstolo.



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