I have a C library that is not threadsafe — and probably will never be. I’m calling it from C# with PInvoke and that’s working out quite nicely.
Now that C library has to be called from a C# program that certainly is multi-threaded. I can manage this in the C# by having each instance of the C code called from separate AppDomains, except that doesn’t seem to be working out very well. I’m still getting a lot of cross-thread problems in the C library.
Will AppDomains isolate the C code mess (globals, etc..) from each other or no? If not, what will?
No, AppDomains will not help. If you call into your C lib concurrently, it doesn’t matter which AppDomain the calls come from.
If the C lib is not thread-safe, you will have to serialize access to it. Actually, having multiple AppDomains makes this harder – you will have to synchronize across the domains.