Can .NET Task instances go out of scope during run?

Posted by Henry Jackson on Stack Overflow See other posts from Stack Overflow or by Henry Jackson
Published on 2010-05-06T16:43:57Z Indexed on 2010/05/06 16:48 UTC
Read the original article Hit count: 246

If I have the following block of code in a method (using .NET 4 and the Task Parallel Library):

var task = new Task(() => DoSomethingLongRunning());
task.Start();

and the method returns, will that task go out of scope and be garbage collected, or will it run to completion? I haven't noticed any issues with GCing, but want to make sure I'm not setting myself up for a race condition with the GC.

© Stack Overflow or respective owner

Related posts about .NET

Related posts about task-parallel-library