Is necessary to lock this function, when updating the shared Array using many threads?, providing that each Arrays element is accessed (read and written), by only 1 thread at most.
Thank you.
e.g.
public string[] UpdateArray
(List<string> myList, Func<string,string>del)
{
int count = myList.Count;
string[] myArray = new string[count];
Parallel.For(0, count, i => myArray[i] = del(myList[i]));
return myArray;
}
update:
its intended use would be as follows,in a WPF sync context
public Task<string[]> updateArrayTask()
{
List<string> myList = GetMyList();
Func<string, string> del = MyDel;
var t1=Task<string[]>.Run(() => UpdateArray(myList, del));
return t1;
}
and then await this Task in an async function.