I can't seem to understand why this won't work. I've searched endlessly and don't see how my example below doesn't kick off an asynchronous operation.
void Folder::NewFileAction()
{
if (Folder::Match)
{
LOG(LOG_INFO) << "New file detected. Compressing";
auto Compress = async(launch::async, &ZipFile, Folder::FilePath);
}
}
Shouldn't this kick off an asynchronous operation in another thread? Is there a flag I have to enable in Visual Studio 2015?
Thank you
std::async
returns a std::future
object. Since Compress
is local object (of type std::future
), and will go out of scope. Since this is only object holding the async
return result, the destructor will keep on waiting. You should keep such object(s) in member of this class (a vector<future>
may be).
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With