Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Remove completed tasks from List<Task>

I am using TPL in .net 4.0 to work with multiple tasks asynchronously. The following is the code snippet:

List<Task> TaskList = new List<Task>();
while (some condition)
{
    var t = Task.Factory.StartNew( () = > doSomething () );
    TaskList.Add(t)
}

//Wait for all tasks to complete
Task.WaitAll(TaskList.toArray());

If the while loop runs for a long time, what happens to the size of "TaskList"? I am concerned that this is going to take up significant memory if the while loop runs for a couple of days. Do I have to remove completed tasks from that list or do they get disposed automatically?

Is there any other way to optimize this in terms of memory?

like image 898
Andy Avatar asked Sep 05 '14 13:09

Andy


People also ask

How do I delete completed tasks from task list in Outlook?

Step 2: Click the Change View > Completed on the View tab. If you are using Microsoft Outlook 2007, please click the View > Current View > Completed Tasks. Step 3: Select all completed tasks with pressing the Ctrl + A keys on the keyboard, and then remove them all with pressing the Delete key.

How do I delete completed tasks in to do?

Go to Settings. Open the 'Completed Tasks' folder. Tap on “Delete All”.

How do I hide completed tasks in Microsoft planner?

Go to the Project menu and click on Autofilter option. Click on the autofilter arrow next to the % complete column heading and uncheck 100% value. All the completed tasks will be hidden and only the tasks that are in progress will be displayed.


1 Answers

TaskList.RemoveAll(x => x.IsCompleted);

Do I have to remove completed tasks from that list or do they get disposed automatically?

no, nobody will remove entries of your List if you don't.

like image 64
ths Avatar answered Sep 19 '22 09:09

ths