N
Nathan
I'm trying to find the proper way to dispose of my application instance. I
have a WordManager class that contains an Application as a member variable
(m_oApp). I made my class IDisposable and inside the destructor I call a its
dispose function which attempts to execute the following code:
object missingValue = Type.Missing;
object objDoNotSave = WdSaveOptions.wdDoNotSaveChanges;
if (this.m_oApp != null)
{
this.m_oApp.Quit(ref objDoNotSave, ref missingValue, ref missingValue);
this.m_oApp = null;
}
This application runs in the background without a UI so I can't just use the
Windows.Forms dispose events like I normally would.
This quit function works fine during normal runtime, but when I invoke it
from the destructor of my WordManager it gives me the following exception
and it never kills the winword.exe process.
InvalidObjectException
COM object that has been separated from its underlying RCW cannot be used.
I've considered several work-around options.
One, I can simply find a process that matches the name and timestamp of when
I instantiated ApplicationClass. (I don't want to do that because I might
actually have more than one legitimate instance of Word running at a time).
Two, I've searched the object model to see if I can find a handle or a
process id that I can just manually kill the winword.exe that belongs to
this instance.
Three, I can properly dispose the com instance and let it shut itself down.
(my preference).
What is the proper way to dispose of my COM word object when shutting down
the application?
Thanks in advance,
Nathan Bridgewater
have a WordManager class that contains an Application as a member variable
(m_oApp). I made my class IDisposable and inside the destructor I call a its
dispose function which attempts to execute the following code:
object missingValue = Type.Missing;
object objDoNotSave = WdSaveOptions.wdDoNotSaveChanges;
if (this.m_oApp != null)
{
this.m_oApp.Quit(ref objDoNotSave, ref missingValue, ref missingValue);
this.m_oApp = null;
}
This application runs in the background without a UI so I can't just use the
Windows.Forms dispose events like I normally would.
This quit function works fine during normal runtime, but when I invoke it
from the destructor of my WordManager it gives me the following exception
and it never kills the winword.exe process.
InvalidObjectException
COM object that has been separated from its underlying RCW cannot be used.
I've considered several work-around options.
One, I can simply find a process that matches the name and timestamp of when
I instantiated ApplicationClass. (I don't want to do that because I might
actually have more than one legitimate instance of Word running at a time).
Two, I've searched the object model to see if I can find a handle or a
process id that I can just manually kill the winword.exe that belongs to
this instance.
Three, I can properly dispose the com instance and let it shut itself down.
(my preference).
What is the proper way to dispose of my COM word object when shutting down
the application?
Thanks in advance,
Nathan Bridgewater