Are there some general advice about using multithreading when calling unmanaged code?
I randomly receive access violation errors and obviously digging into that unmanaged code doesn’t make much sense.
Are there some approaches I could try instead of putting these calls into some sort of a critical section to remove violation errors?
It depends on whether the unmanaged component you are calling is programmed threadsafe or not.
If you are getting access violations only when calling this code in parallel it looks like the component you are using is not threadsafe.
Use the C#
lock()statement to make it secure: