You should probably think about using a Singleton Pattern, to make sure that only one instance of Microsoft.Office.Interop.Word.Application object is ever created.
A singleton Pattern is a tried an tested design pattern wherein the consumer of a class make sure that only one instance of a class is ever created.
Check out a basic implementation of it below:
public class WordInstanceSingleton
{
private static Microsoft.Office.Interop.Word.Application m_wordInstance;
private WordInstanceSingleton() {}
public static Microsoft.Office.Interop.Word.Application Instance
{
get
{
if (m_wordInstance == null)
{
m_wordInstance = new Microsoft.Office.Interop.Word.Application();
}
return m_wordInstance ;
}
}
}
In the place where you create an instance of the Microsoft.Office.Interop.Word.Application class replace it with the following code:
Microsoft.Office.Interop.Word.Application wordApp = WordInstanceSingleton.Instance;
There are many variations of the SingletonPattern, and if your compare code exists within a multi-threaded environment, then you will have to make changes in the Singleton Pattern. Read more about it
here.Though always keep in mind that the WordApplication is not designed to work in a multi-threaded environment, and if you make your application work with the same instance on multiple documents, it might not work predictably and will be unstable.
Also, remember that you will have to make sure that the Microsoft.Office.Interop.Word.Application should be disposed using either "Quit()" or Close()method, once the comparison is done or when you close the application.