I wrote a library on top of System.Data.SQLite
and realized it (my library) has unpredictable behaviour when using Parallel.ForEach
. I might debug this eventually (ie if I get/take the time), most likely by locking the right parts, but for now let's say I want to just prevent usage of Parallel.ForEach
, or force usage of my library to allow (or result in) only a single thread, how would I proceed?
You can't control how your API is consumed by external code. If it's something you absolutely cannot address prior to release, it would be a good idea to be very explicit about failure cases in your documentation (both XML comments and any sort of "help file").
A few quick threadstatic attributes might solve your concurrency problem, but this smells like the tip of a much larger iceberg. Fix the root cause, not the symptom.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.