async/await and mutexes
I have a service that i will inject it as singleton that has:
and I want the dictionary to be lazy initialized only once when needed like:
but when I invoke and wait for the FromTo Task that returns a list of strings the context changes and when i release the mutex it crashes because i release it from an another thread, the exception message looks like this: "Object synchronization method was called from an unsynchronized block of code."
Even if i add ConfigureAwait(true) doesn't switch the context to the captured one.
Any idea why this happens or how can I do it differently?
Thank you in advance
and I want the dictionary to be lazy initialized only once when needed like:
but when I invoke and wait for the FromTo Task that returns a list of strings the context changes and when i release the mutex it crashes because i release it from an another thread, the exception message looks like this: "Object synchronization method was called from an unsynchronized block of code."
Even if i add ConfigureAwait(true) doesn't switch the context to the captured one.
Any idea why this happens or how can I do it differently?
Thank you in advance