Only allow one copy of Reinterop to run at a time. #403
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This fixes a problem noticed by @j9liu and @azrogers where Reinterop would leave a bunch of stale generated files lying around while renaming a class in Visual Studio. For example:

This happens because each time you press a key during the rename, Visual Studio starts a new compilation for Intellisense, without waiting for the previous one to finish. Each compilation runs Reinterop. There's apparently no (official? reliable?) way for Reinterop to detect that it's running inside Intellisense rather than a normal compilation. These multiple running copies of Reinterop race against each other to update the
reinterop-inventory.txt
file that keeps track of the .cpp and .h files that were generated, and so the contents of that file can get out of sync with the files that actually exist on the file system. When this happens, the next run of Reinterop won't know to clean up some of the files, and you end up with stale files lying around.So my solution here is to wrap a giant named (system-global) semaphore around Reinterop so only one copy can run at a time, and any additional invocations will wait. Kind of terrible, but effective. I don't expect this will work anywhere but Windows due to lack of support for named, system-wide semaphores. But it should fail in such a way that just allows multiple copies of Reinterop to run, so it's no worse than before. There's also potential for an impact on Intellisense performance. It seems mostly ok to me, but let me know what you think.
As always with a Reinterop update, it's necessary to rebuild it (
dotnet publish Reinterop~ -o .
) and then restart Visual Studio for the new version to get picked up.