How to Cancel and Restart A Task

Nov 21, 2014 at 8:31 AM
I search something on server by the following code where g_token is an object of pplx::cancellation_token_source.

http_resp = client.request(request, g_token.get_token()).get(); // Request Task

and stop searching in a Message Response Function OnStop() by
g_token .cancel();

then I restart the search but the Request Task always throw an exception "operation canceled".

How can I reset the cancellation token?
Nov 21, 2014 at 5:47 PM
Hi joeccmou,

Both a task and a cancellation_token/cancellation_token_source are single use objects, as in they can't be reset back to a beginning or not canceled state. You will have to recreate a new cancellation_token_source when you want to retry the request.