-2

instruction from my code:

streamIdentical.Write(files[LEFT].subFilepath[leftFileIndex] + ", " + 
files[RIGHT].subFilepath[rightFileIndex] + " " + 
files[LEFT].status[leftFileIndex] + "\n");

I copied the variable strings to Watch Window and they evaluate to valid strings every time it fails! They are not excessively long(approx 50 chars, 50 chars, 15 chars) strings.

I am processing the exact string[] of filepaths each time, BUT it fails at a different leftFileIndex and rightFileIndex each time!

Exception claims "count" is <0, count is 4th parameter passed to CopyTo().

Is this a bug in the dll?

Eric J.
  • 147,927
  • 63
  • 340
  • 553
spinlock
  • 17
  • 3
  • 1
    Can you please share the whole code snippet? – Guru Stron Mar 10 '21 at 16:29
  • That is the entire failing instruction. ADD COMMENT character limitations do not allow me to post very much. Here is pseudo code: streamWriter.Write(validString0 + ", " + validString1 + " " + validString2 + "\n"); NOTE: the strings were valid per the debug Watch Window. – spinlock Mar 10 '21 at 17:11
  • You can post here pretty big code snippets. I mean edit the question, not in the comments. – Guru Stron Mar 10 '21 at 17:18
  • Thanks Guru Stron! When I went back to code to Copy more, I saw something that allowed me to understand issue MUCH better. This line follows the failing instruction: ++metrics[threadID].identical; I had totally glossed over the fact tthta my app is multi-threaded! That DLL is not re-entrant. How do I configure VS2019 to use multi-thread safe common code? – spinlock Mar 10 '21 at 17:28
  • VS does not have anything to do with thread safety) You mean how to do threading in C#? – Guru Stron Mar 10 '21 at 17:32
  • > VS does not have anything to do with thread safety --- with other languages under VS, there are LINK options to pick MT libraries and embed all code into .exe. If you are saying VS/C# does not have anything to do with thread safety, then: I know how to make my code thread safe, I have [MTAThread] before the main(it is a Form app), what else do I need? – spinlock Mar 10 '21 at 18:09
  • I'm saying that VS is an IDE =) – Guru Stron Mar 10 '21 at 18:18
  • If the only answer is build some form of synchronization into my code, I can do that too. But, still hoping there are MT libraries/DLLs for all methods and some way to use them. – spinlock Mar 10 '21 at 18:44

1 Answers1

0

Thanks for your help Guru Stron!

It seems the answer is not all C# Classes have thread safe versions. I found ConcurrentQueues, that are explicitly thread safe, and I will route all the output to CQs. The Main thread can consume them and write to the output files while it is waiting for all the threads to finish.

Thanks again!

spinlock
  • 17
  • 3