Here's my current test case code:
> #include <Wt/WApplication>
> #include <Wt/WPushButton>
> #include <Wt/WLineEdit>
>
> #include <iostream>
> #include <boost/thread.hpp>
>
> using namespace Wt;
> using namespace boost;
> using namespace std;
>
> class ExampleWidget;
> class CometTestApplication : public WApplication
> {
> public:
> CometTestApplication(const WEnvironment& env);
> ExampleWidget *t;
> };
>
> class ExampleWidget : public WLineEdit
> {
> boost::thread updater;
>
> public:
> void startBigWork()
> {
> updater = boost::thread(boost::bind(&ExampleWidget::doWork, this,
> WApplication::instance(), text()));
>
> wApp->enableUpdates(true);
> }
>
> ExampleWidget()
> {
> keyWentUp().connect(SLOT(this, ExampleWidget::startBigWork));
> }
>
> void doWork(WApplication *app, const WString s)
> {
> CometTestApplication *myApp = static_cast<CometTestApplication
> *>(app);
> myApp->attachThread();
>
> // do work...
>
> // if you want to update the GUI:
> {
>
> WApplication::UpdateLock uiLock = myApp->getUpdateLock(); // RAII
> lock
> cout << endl << s << endl;
>
> myApp->t->setText(s + s);
>
> cout << endl << myApp->t->text() << endl;
>
> // if using server push, push now the changes to the client
> myApp->triggerUpdate();
> }
>
> // finally, when the work is done, we can disable updates again
> myApp->enableUpdates(false);
> }
>
> };
>
> CometTestApplication::CometTestApplication(const WEnvironment& env)
> : WApplication(env)
> {
> t = new ExampleWidget();
>
> root()->addWidget(t);
> }
>
> WApplication *createApplication(const WEnvironment& env)
> {
> return new CometTestApplication(env);
> }
>
> int main(int argc, char **argv)
> {
> return WRun(argc, argv, &createApplication);
> }
>
It occasionally runs on my session but most of the time it doesn't. When it
does it just sets it a lot of times.
It doesn't update any sessions.
It looks like the thread is taking forever to run comparing to normal code.
Any idea why?
2010/1/20 Wim Dumon <[email protected]>
> Omer,
>
> Koen posted an example of a worker thread on the mailing list not very
> long ago. Could you search in the archives?
>
> Regards,
> Wim.
>
> 2010/1/19 omer katz <[email protected]>:
> > Could you show me how such worker thread would look like?
> > The keyword is should but it doesn't.
> > 2010/1/19 Koen Deforche <[email protected]>
> >>
> >> Hey Omer,
> >>
> >> 2010/1/19 omer katz <[email protected]>:
> >> > Currently I have a function that triggers updates whenever my slider's
> >> > value
> >> > changes:
> >> >>
> >> >> void updateChanges()
> >> >> {
> >> >> wApp->enableUpdates();
> >> >> Wt::WApplication::UpdateLock lock(wApp->getUpdateLock());
> >> >> wApp->triggerUpdate();
> >> >> }
> >>
> >> The enableUpdates() and triggerUpdate() methods are used to push
> >> visual changes of a particular application to the client, from outside
> >> the event loop (another thread or, like in the simple chat example,
> >> another application). So you either need to at least have another
> >> (worker) thread or intra-application communication for these methods
> >> to be useful.
> >>
> >> > Unfortunately it doesn't update the slider like it's expected to.
> >>
> >> If it was a client event that ultimately resulted in a slider value
> >> change, then it should be propagated when the event handling finishes.
> >> If you have a long event handling, then you can use
> >> WApplication::propagateChanges() to update the user interface at
> >> intermediate time points. However, this solution is inferior than
> >> using a worker thread because it still freezes the user interface
> >> while the event handling is busy.
> >>
> >> > The documentation doesn't show examples for updating widgets.
> >>
> >> Because widgets are updated automatically.
> >>
> >> > What are the requirements for updating widgets?
> >> > How does a widget knows it's contemporaries?
> >>
> >> Every widget keeps track of changes to it.
> >>
> >> Regards,
> >> koen
> >>
> >>
> >>
> ------------------------------------------------------------------------------
> >> Throughout its 18-year history, RSA Conference consistently attracts the
> >> world's best and brightest in the field, creating opportunities for
> >> Conference
> >> attendees to learn about information security's most important issues
> >> through
> >> interactions with peers, luminaries and emerging and established
> >> companies.
> >> http://p.sf.net/sfu/rsaconf-dev2dev
> >> _______________________________________________
> >> witty-interest mailing list
> >> [email protected]
> >> https://lists.sourceforge.net/lists/listinfo/witty-interest
> >
> >
> ------------------------------------------------------------------------------
> > Throughout its 18-year history, RSA Conference consistently attracts the
> > world's best and brightest in the field, creating opportunities for
> > Conference
> > attendees to learn about information security's most important issues
> > through
> > interactions with peers, luminaries and emerging and established
> companies.
> > http://p.sf.net/sfu/rsaconf-dev2dev
> > _______________________________________________
> > witty-interest mailing list
> > [email protected]
> > https://lists.sourceforge.net/lists/listinfo/witty-interest
> >
> >
>
>
> ------------------------------------------------------------------------------
> Throughout its 18-year history, RSA Conference consistently attracts the
> world's best and brightest in the field, creating opportunities for
> Conference
> attendees to learn about information security's most important issues
> through
> interactions with peers, luminaries and emerging and established companies.
> http://p.sf.net/sfu/rsaconf-dev2dev
> _______________________________________________
> witty-interest mailing list
> [email protected]
> https://lists.sourceforge.net/lists/listinfo/witty-interest
>
------------------------------------------------------------------------------
Throughout its 18-year history, RSA Conference consistently attracts the
world's best and brightest in the field, creating opportunities for Conference
attendees to learn about information security's most important issues through
interactions with peers, luminaries and emerging and established companies.
http://p.sf.net/sfu/rsaconf-dev2dev
_______________________________________________
witty-interest mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/witty-interest