Reputation: 45
I have list of tasks run based on the queue but i need to check if the task is completed or not. Based on the status returned from each task i have to execute the function.
Task.Factory.StartNew(
() =>
{
string fileName;
while (!filePaths.IsCompleted)
{
if (!filePaths.TryTake(out fileName)) continue;
this.ReadFileContents(fileName, VMCallBack);
}
}, _cts.Token);
Upvotes: 0
Views: 67
Reputation: 977
Task myTask = Task.Factory.StartNew(...);
myTask.Wait();
//now do stuff after completion
Upvotes: 1
Reputation: 5505
StartNew
returns a object of Task
. You can collect those and check the IsCompleted
property to find out if it is completed or not.
Upvotes: 1