
I'm using an ASIO extention that was suggested for file monitoring. I've added this to my project and though I see a change when I add a file to the directory being monitored, I see no futher changes thereafter. Can anyone offer some insight as to how this should work? Any help much appreciated. void create_file_handler(const boost::system:error_code &ec, const boost::asio::dir_monitor_event &ev) { cout << "file name: " << ev.filename << endl; cout << " type : " << ev.type << endl; // now edit file ... } // from within main() boost::thread t; { boost::asio::io_service io_service; boost::asio::dir_monitor dm(io_service); dm.add_directory("C:\\Users\\SRD\\DirA"); boost::asio::dir_monitor_event ev = dm.monitor(); dm.async_monitor(create_file_handler); t = boost::thread(boost::bind(&boost::asio::io_service::run, boost::refio_service))); boost::system_time time = boost::get_system_time(); time += boost::posix_time::time_duration(0, 0, 1); boost::thread::sleep(time); } t.join(); io_service.reset(); // now do app stuff ..

On Wed, 10 Apr 2013 20:43:15 +0200, SRD
[...]Can anyone offer some insight as to how this should work? Any help much appreciated.
I strongly recommend you to read the tutorial at http://www.boost.org/doc/libs/1_53_0/doc/html/boost_asio/tutorial.html or the chapter http://en.highscore.de/cpp/boost/asio.html from where you downloaded the file monitor to get a basic understanding how Boost.Asio is used.
[...] boost::asio::io_service io_service; boost::asio::dir_monitor dm(io_service);
dm.add_directory("C:\\Users\\SRD\\DirA");
boost::asio::dir_monitor_event ev = dm.monitor(); dm.async_monitor(create_file_handler);
You should call either monitor() or async_monitor(). The first is a blocking call, the second an asynchronous call. The call to monitor() only returns when something happened. If nothing happens monitor() never returns. async_monitor() returns immediately though. And when something happens create_file_handler() is called. Boris
[...]

<...>
{ boost::asio::io_service io_service; boost::asio::dir_monitor dm(io_service);
dm.add_directory("C:\\Users\\SRD\\DirA");
boost::asio::dir_monitor_event ev = dm.monitor(); dm.async_monitor(create_file_handler);
t = boost::thread(boost::bind(&boost::asio::io_service::run, boost::refio_service))); boost::system_time time = boost::get_system_time(); time += boost::posix_time::time_duration(0, 0, 1); boost::thread::sleep(time); }
Note that at this point io_service and dm get destroyed.
participants (3)
-
Boris Schaeling
-
Igor R
-
SRD