✅ async/await and parallelism
the problem that spawned this question is that i get a "collection was modified" exception and i don't know why that is
the code is a client for a device, the
so i understand that asynchronous model has following properties:
- multithreading: yes, easily verifiable (thread pool, background threads, and all that)
- concurrency: yes, that's the whole point of async/await
- parallelism: no, probably?
and yet in some way in a method that is not even async i get the exception above
so then my question is: considering i don't (explicitly) create ither threads and i don't use Task.Run, is it possible that the use of
i know i can add a
the code is a client for a device, the
_message linked list is being accessed in three ways: from a heartbeat loop, from the i/o eventhandler, and from the public methods of the commands -- after an await (also _messages is never enumerated with a for/foreach) so i understand that asynchronous model has following properties:
- multithreading: yes, easily verifiable (thread pool, background threads, and all that)
- concurrency: yes, that's the whole point of async/await
- parallelism: no, probably?
and yet in some way in a method that is not even async i get the exception above
so then my question is: considering i don't (explicitly) create ither threads and i don't use Task.Run, is it possible that the use of
await method() could cause some sort of parallelism? or could code get parallel execution by some other practice? (again, excluding creating other threads) i know i can add a
lock or use a concurrent collection or use a channel, but i am given this tool, async/await, i have a mental model of it, but evidently something is wrong, and i cannot use it if i don't know how it works