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?
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.
Go to Settings. Open the 'Completed Tasks' folder. Tap on “Delete All”.
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.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With