I built a Fortran DLL with the Runtime Library option (Multithread DLL (/libs:dll /threads)). We are attempting to use this DLL in a multithreaded .NET code. The issue is that there are files being created in the intermediary folder that are being overwritten and accessed many times, which throws an error. I see some files named fort.20 or fort.80. I think those files are temporary files for the output files that are labeled 20 and 80 in the Fortran code. Is there a way to prevent this from happening? Or is there a successful robust way to use the DLL in a multithreaded .NET code?
Yes, if you write to unit 20 (for example) without OPENing a file, you'll get a file called fort.20. If your DLL is being called from a multithreaded environment, it isn't sufficient to link to the thread-safe run-time DLLs (which nowadays all of the Fortran run-time DLLs are.) Your own code has to be thread-safe, which means work on your part. In the case of temporary files, you could open the units with STATUS='SCRATCH' and they would have unique names (and be in the TEMP folder), or you could work out your own way to separate the files opened in different threads.
At a minimum you will want all procedures to be RECURSIVE (this is the default in Fortran 2018, so if you are using the oneAPI compiler you are covered there.)