Click here to Skip to main content
15,886,806 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
C#
runningTasks.Add(Task.Run(() => ProcessTagsValidationInsertion(tvlFileTracker, tempRemainderTags)));
Array.Clear(tempRemainderTags, 0, tempRemainderTags.Length);

tempRemainderTags - Array of Objects

Post I clear array out side of the Task, the elements which were passed to Task is becoming null.

Can someone tell me how to clear the source of Task, I need to refill that array and pass to the same task again.

What I have tried:

I have tried keeping the array, but this would not give proper results.
Posted
Updated 4-Nov-19 3:34am
v2

1 solution

The task gets a pointer to the array objects, not a copy. So when you clear the array, the pointer leads to an empty array. You can pass a clone of the array, that will work:

runningTasks.Add(Task.Run(() => ProcessTagsValidationInsertion(tvlFileTracker, tempRemainderTags.Clone)));
 
Share this answer
 
Comments
Richard Deeming 5-Nov-19 15:31pm    
Clone is a method, so you'll need to add the parentheses to the call:
tempRemainderTags.Clone()

It also returns object rather than a strongly-typed array, so you'd also need to add a typecast.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900