I know in multithreading program, we need to use ConcurrentDictionary
, ConcurrentBag
etc those thread-safe collection. But in my situation, the number of keys in Dictionary is fixed, I have exact 5 keys which I already know before the program executes so I can initialize the dictionary's key. So my thinking is, because the number of the keys is not going to change, I can actually use Dictionary
instead of ConcurrentDictionary
, and the reason I am thinking to do this, is because the collection won't resize internally, so there won't be a situation when thread1 try to update an element after thread2 adds a new element then cause resizing, which makes thread1's update fail. Is my understanding correct?
More information:
I don't have a shared key/value pair that can be updated by all threads, each thread just update a particular key/value pair and TKey is a unique string, TValue is simple class type