This is possibly a silly question, but do I need to use and assignment with a lock, or can I simply return the results.
For example:
I have a private helper method that returns an IEnumerable list of file names. It uses a lock to ensure the method is thread safe while it is iterating around the m_transfers collection.
Do I need an assignment...
IEnumerable<String> updated;
lock (m_transfers.Lock)
{
updated = m_transfers.Values.Where(transfer => transfer.Updated)
.Select(transfer => transfer.Filename);
}
return updated;
Or can I just do
lock (m_transfers.Lock)
{
return updated = m_transfers.Values.Where(transfer => transfer.Updated)
.Select(transfer => transfer.Filename);
}