I have a while loop in a windows service which runs for some x times and inititate x phone calls after reading them from some file . Now if i want to make a user interface which gives an option to stop the phone calls i.e. break the while loop even before it is completed. How shall i do it ?
Lets suppose i have a function .
DialCalls(x)
{
for(int i= 0 ; i<x ; i++)
{
// Initiate call
}
}
There can be 2,3 DialCalls functions running at the same time in different threads as i have done threading in the application as well . So basically what is best way to break the loop from a webpage maybe.
Using task cancellation ( new in .net 4):
http://blogs.msdn.com/b/csharpfaq/archive/2010/07/19/parallel-programming-task-cancellation.aspx
The task swallows exceptions so there is some cleanup to to, maybe as IDisposable?
About task exceptions