I use some REST requests using Mono.Mac (3.2.3) to communicate with the server, and as a retry mechanism, I calmly try to give several attempts an HTTP action, if they fail, or a timeout.
I have the following:
var tries = 0; while (tries <= ALLOWED_TRIES) { try { postTask.Start(); tries++; if (!postTask.Wait(Timeout)) { throw new TimeoutException("Operation timed out"); } break; } catch (Exception e) { if (tries > ALLOWED_TRIES) { throw new Exception("Failed to access Resource.", e); } } }
If the task uses the parameters of the parent method, for example:
var postTask = new Task<HttpWebResponse>(() => {return someStuff(foo, bar);}, Task.Factory.CancellationToken, Task.Factory.CreationOptions);
The problem is that after the first completion (and subsequent failure), the task does not want to start again with postTask.Start() . Is there an easy way to do this, or am I misusing tasks in this way? Is there any method that resets the task to its original state, or is it better for me to use some kind of factory?
source share