ehafeez
ehafeez

Reputation: 45

How to get the task is finished / Completed?

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

Answers (2)

coffee-converter
coffee-converter

Reputation: 977

Task myTask = Task.Factory.StartNew(...);
myTask.Wait();
//now do stuff after completion

Upvotes: 1

ZoolWay
ZoolWay

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

Related Questions