#ifndef _DEBUG #pragma comment(lib, "wt.lib") #pragma comment(lib, "wthttp.lib") #else #pragma comment(lib, "wtd.lib") #pragma comment(lib, "wthttpd.lib") #endif #include #include #include #include #include #include #include #include #include #include #include #include #include #include // CMD: // C:> server.exe --http-address 0.0.0.0 --docroot C:\Users\user\source\repos\emweb\wt-install\share\Wt class MyApp : public Wt::WApplication { private: Wt::WText* text{}; std::atomic count{}; int dlgCount{}; std::vector threads; public: static std::unique_ptr CreateApp (const Wt::WEnvironment& env) { return std::make_unique(env); } void OpenDialog () { auto dlg = addChild(std::make_unique("This dialog should be unique, but it's count is: " + std::to_string(++dlgCount))); dlg->resize(450, -1); dlg->setModal(true); dlg->setClosable(true); dlg->finished().connect([&] () { removeChild(dlg); --dlgCount; }); dlg->show(); } void Work () { const auto sessionid = wApp->sessionId(); const auto finishcb = bindSafe([&] () { std::this_thread::sleep_for(std::chrono::seconds(5)); // simulate a slow responding server if (--count == 0) { text->setText("done"); } else { text->setText("loading: " + std::to_string(count)); } wApp->triggerUpdate(); wApp->enableUpdates(false); }); constexpr int CONCURRENCY = 1; for (int i = 0; i < CONCURRENCY; ++i) { ++count; wApp->enableUpdates(true); threads.push_back(std::thread{[sessionid, finishcb] () { Wt::WServer::instance()->post(sessionid, finishcb); }}); } } ~MyApp () { for (auto& t: threads) { t.join(); } } MyApp (const Wt::WEnvironment& env) : Wt::WApplication(env) { auto layout = root()->setLayout(std::make_unique()); auto btn = layout->addWidget(std::make_unique("open dialog")); btn->clicked().connect(this, &MyApp::OpenDialog); text = layout->addWidget(std::make_unique("warming up, smash dialog button to produce error!")); layout->addStretch(1); Work(); } }; int main(int argc, char** argv) try { Wt::WServer wserver{argc, argv}; wserver.addEntryPoint(Wt::EntryPointType::Application, &MyApp::CreateApp); wserver.run(); return wserver.waitForShutdown(); } catch (std::exception& e) { std::cerr << e.what() << std::endl; return EXIT_FAILURE; }