I'm working on a .NET requirements management add-in for EA that integrates viewing of linked documents together with the normal requirement attributes (and then some). To allow advanced editing of the linked documents (beyond the editing capability offered by a .NET RichTextBox), I fire up Wordpad and load the linked document into it (after saving the linked doc to a temp file); this allows the user to remain within the add-in environment to do fancy editing without having to open EA's document editor. The add-in then "waits" for Wordpad to close, reads the modified file back into the linked document, then updates the display. The problem is the "wait" doesn't wait at all... the add-in blows right through the wait statement and updates the linked document with the original temp file - in other words, without the changes made in Wordpad. Adding a message box to the code, however, forces a wait (until it's closed at least); this "fixes" the wait problem and the update to the linked doc is now successful.
Here's the (C#) code:
private void editToolStripMenuItem_Click(object sender, EventArgs e)
{
bool res;
if (this.processEditor == null)
{
this.processEditor = new System.Diagnostics.Process();
this.processEditor.EnableRaisingEvents = true;
}
tempdoc = Environment.GetFolderPath(Environment.SpecialFolder.Personal) + "\\EA_" + Guid.NewGuid().ToString().Replace("{", "").Replace("}", "") + ".rtf";
theRequirement.SaveLinkedDocument(tempdoc);
processEditor.StartInfo.FileName = Strings.AdvancedEditor; // C:\Windows\write.exe in this case
processEditor.StartInfo.Arguments = tempdoc;
processEditor.Start();
processEditor.WaitForExit(); // This happens immediately; it doen't wait for the process to exit...
MessageBox.Show(processEditor.HasExited.ToString()); // This provides the required wait to allow the process to exit!
res = theRequirement.LoadLinkedDocument(tempdoc);
res &= theRequirement.Update(); // Unsure whether this is needed, but what the heck.
this.rtfEditor1.TheRichTextBox.Rtf = theRequirement.GetLinkedDocument();
this.rtfEditor1.Refresh();
processEditor.Dispose();
processEditor = null;
}
This seems to be a Windows problem rather than an EA problem, but I'm hoping that the Sparxians or one of our crackerjack EA gurus (and there are quite a few of them on this forum) can offer some advice. It's as if the wait call, viewed metaphorically as a yodeler waiting to hear his/her echo return from across a wide valley (!), has his/her yodel bounced back immediately by an invisible wall (non-metaphorically, the COM barrier of the add-in model or the EA process itself?). I'm no Win32 expert, so this is just a wild guess (a yodel in the dark?)
Cheers,
Fred W
PS: I know, I need to add code to clean up the temp file...