Hi,
You can use:
WaitForSingleObjectEx(smi_event_wait,1000,false);
it can sleep 1 second and add a cancellation taken in the constructor then cancel the task:
task<void>(create_async([]() {
auto s = ref new StreamSocket();
/*
* Connect to host
*/
task<void>(s->ConnectAsync(ref new HostName(ref new Platform::String(L"google.com")), ref new Platform::String(L"80"))).get();
auto reader = ref new DataReader(s->InputStream);
cancellation_token_source read_operation;
WRL::Wrappers::Event evt(CreateEventExW(NULL, NULL, CREATE_EVENT_MANUAL_RESET, EVENT_ALL_ACCESS));
/*
* Start reading
*/
task<unsigned int>(reader->LoadAsync(100), read_operation.get_token()).then([&evt](task<unsigned int> t){
try
{
unsigned int num_read = t.get();
}
catch (...)
{
}
SetEvent(evt.Get());
});
WaitForSingleObjectEx(evt.Get(), 1000, FALSE);
/*
* Cancel the operation after 2 seconds of wait
*/
read_operation.cancel();
FALSE);
})).then([](task<void> t) {});
You can refer to the link below:
http://msdn.microsoft.com/en-us/library/windows/apps/dd984117.aspx#tasks
Best Wishes!
We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place. <br/> Click <a
href="http://support.microsoft.com/common/survey.aspx?showpage=1&scid=sw%3Ben%3B3559&theme=tech"> HERE</a> to participate the survey.