2
Answers

Aborting a Service safe

Hakan Axheim

Hakan Axheim

3y
503
1
Hi,
 
I have a service that do some work with a polling intervall.
Task task = new Task( delegate { DoWork(); });
task.Wait(Convert.ToInt32(ConfigurationManager.AppSettings["PollingInterval"]));
task.RunSynchronously();
 
My question is how to abort the Task safe?
 
Is it enough with
 
try
   Task task = new Task( delegate { DoWork(); });
   task.Wait(Convert.ToInt32(ConfigurationManager.AppSettings["PollingInterval"]));
   task.RunSynchronously();
}
catch (ThreadAbortException threadAbortException)
{
   // Clean up 
 
Answers (2)