F
Fruber Malcome
I have a C# application that starts as a form.
This form has a member that holds an instance of a CustomClass that
automates word by creating new commandbards / hiding others and handling the
messages from them.
The instance of this object is created during the initialize even of the
form.
If I click exit on word, it closes this form (just a blank form for now)
If I click exit on the form (the x button) - it closes both the form and
word.
Once the initialize of the form is complete and word has started - all of my
commandbars, menubars all appear and messages are handled.
If after sometime goes by (opening dialogs / closing dialogs etc - something
that creates objects and let's them get disposed) - all of a sudden none of
my message handlers are working. - I get the macro not found or security
setting too high error message.
I put some thought into it and assumed it must have had something todo with
garbage collection, so I then call (for testing purposes):
GC.Collect()
GC.WaitForPendingFinalizers()
at the end of my initialize function (in the form)
Everything acted the same.
I then put this same exact two lines of code at the end of my constructor in
the AutomationClass, and now after initialization - it all stops working
immediately.
I still have all my commandbars etc, but the handlers immediatly stop
working.
I've checked the contructor - and functions that are called outside of the
constructor - I see no variables being called only within that scope that
would make any difference.
I've attached WinDebug to this application while running, I see nothing
going on that shouldn't. (no threads exiting or something like that - that
would lead me to isolate the problem).
I suspect it may have something to-do with the fact that because this
application performs all the setup for commandbars and menubars, and then
just waits to handle messages, and because it's not performing word stuff at
this time, that maybe the COM object is getting GC'ed?
Is there a way for me to ping it (by using some timer or something) for me
to keep it going (if this is the case)?
What other workarounds do I have, or is this not the problem at all?
As an additional note: when this happens, if I click close on my Form - the
Word application (after several debugger exceptions about file not found
etc) - finally exits. So this tells me that my _thisApplication object (or
at least in this specific case - my WordAutomation instance) is still valid.
Any help would be greatly appreciated...
thanks - Fruber
This form has a member that holds an instance of a CustomClass that
automates word by creating new commandbards / hiding others and handling the
messages from them.
The instance of this object is created during the initialize even of the
form.
If I click exit on word, it closes this form (just a blank form for now)
If I click exit on the form (the x button) - it closes both the form and
word.
Once the initialize of the form is complete and word has started - all of my
commandbars, menubars all appear and messages are handled.
If after sometime goes by (opening dialogs / closing dialogs etc - something
that creates objects and let's them get disposed) - all of a sudden none of
my message handlers are working. - I get the macro not found or security
setting too high error message.
I put some thought into it and assumed it must have had something todo with
garbage collection, so I then call (for testing purposes):
GC.Collect()
GC.WaitForPendingFinalizers()
at the end of my initialize function (in the form)
Everything acted the same.
I then put this same exact two lines of code at the end of my constructor in
the AutomationClass, and now after initialization - it all stops working
immediately.
I still have all my commandbars etc, but the handlers immediatly stop
working.
I've checked the contructor - and functions that are called outside of the
constructor - I see no variables being called only within that scope that
would make any difference.
I've attached WinDebug to this application while running, I see nothing
going on that shouldn't. (no threads exiting or something like that - that
would lead me to isolate the problem).
I suspect it may have something to-do with the fact that because this
application performs all the setup for commandbars and menubars, and then
just waits to handle messages, and because it's not performing word stuff at
this time, that maybe the COM object is getting GC'ed?
Is there a way for me to ping it (by using some timer or something) for me
to keep it going (if this is the case)?
What other workarounds do I have, or is this not the problem at all?
As an additional note: when this happens, if I click close on my Form - the
Word application (after several debugger exceptions about file not found
etc) - finally exits. So this tells me that my _thisApplication object (or
at least in this specific case - my WordAutomation instance) is still valid.
Any help would be greatly appreciated...
thanks - Fruber