I'm working with a command in C# where we initialize a pack of documents based on certain criteria. It involves a queue of documents being created, edited, and saved. The way we do this is we create the Doc, switch to it, then SendStringToExecute() with a hidden command that does the initializing, saves it to file, then checks the queue to see if there's more and repeats. This way, each document is edited in it's own document context, which we need to do for reasons I can't get into.
It works most of the time, but quite commonly, it crashes at random in such a way that isn't reproducible. After some testing, the problem seems to go away when the second boolean argument of SendStringToExecute(), that is, wrapUpInactiveDoc, is set to true. However, the only problem there is then SendStringToExecute() throws an eInvalidInput error every time it's called, and then crashes when all the commands are complete. The documents end up otherwise unscathed, It's just inconvenient and bad presentation for our clients.
So I want to know, what exactly does wrapUpInactiveDoc = true actually do, why does it throw an eInvalidInput exception, and how can I do this in a way that doesn't throw that error.