I want to develop C# Windows application managing Word documents. I want to recognize that another Word app is opening by another way (e.g. from Windows Start Menu) and I want to create warning about this.
The user can open the Word documents from main window of this application like this hardcoded test running on test button clicked:
myApp = new Word.Application();
Word.Document mydoc1 = myApp.Documents.Open("C://test/doc1.docx");
Word.Document mydoc2 = myApp.Documents.Open("C://test/doc2.docx");
The user can drag and drop texts or images from Treeview of main Window of this application to this opened documents (no problem).
But when the user opens new word app in a different way than by this application (for example, from the Start menu or double clicked WINWORD.EXE etc.), then working with this application is very confusing because drag and drop works correctly only on managed documents opened by this application.
I solve this by instruction for the user that “no other Word app must not be running” and the application will provide warnings about this situation.
I found, that checking at the application start is simple (something like this):
foreach (Process lP in Process.GetProcesses())
{
if (lP.ProcessName == "WINWORD")
{
MessageBox.Show("Word is running, close please");
return;
}
}
But I don’t know how to recognize the situation that new another Word is opened afterwards when my app is already running. I think this checking will start periodically on some timer tick, but I don’t know how to recognize “my Word app” started by my app from the second “foreign Word app” started outside.