I have an in memory static repository which is used both for writing into it and reading from it. When writing (updating) that repository, I would like to make it completely exclusively available for update, without letting reading from it (or even let other process updating it). I'm doing so by using the lock mechanism. In the code below - the UpdateRepoWithItemsBBB is updating the repository with the new Items.
I'm trying to figure out 2 things:
Is the mechanism work as it should ?
What is the reason for the warning message detailed below ? This is my code:
internal async Task UpdateRepo() { IEnumerable itemsAAA = await getItemsFRomApi();
IEnumerable<ClassBBB> itemsBBB = new List<ClassBBB>(); lock(itemsBBB) { itemsBBB = getUpdatedItems(itemsAAA); UpdateRepoWithItemsBBB(itemsBBB) }}
The local variable itemsBBB has a green wavy line beneath it with a warning\notification:
Possibly incorrect assignment to local 'itemsBBB' which is the argument to a using or lock statement. The dispose call or unlocking will happen on the original value of the local.