Reputation: 2764
Okay so I have an application that is using COM to communicate with Quickboos (QBFC). When my application closes, it calls a method to ensure that the connection that has been established with quickbooks is indeed closed before exiting. If I do not call this method, there is the potential for Quickbooks to not allow the user to close their company file because it recognizes an open session with my application, even though it is no longer running.
Now, I am closing the session after I perform my various actions with Quickbooks. I have implemented AppDomain.UnhandledException, Dispatcher.UnhandledException, and Application.Exit event handlers to ensure that if they close the application or an unhandled exception occurs while we have a session open with Quickbooks the session is closed.
This works wonderfully, but now we have an issue during development where if the debugger is stopped before the session is closed, the quickbooks file then becomes locked permanently until we manually end it's process. Any future communications with Quickbooks are in a new session.
Is it possible to have some code execute before the debugger finishes killing the application when I hit 'stop' so we can cleanup our session? Or are we just plain dead in the water? I took a look at the Environment class and I'm 99% certain that it's 'Exit' method is similar to what the debugger is calling when you hit 'stop' so I'm guessing that the answer is 'no'...but I figured it cannot hurt to find out for certain
Upvotes: 1
Views: 977
Reputation: 91
My recommendation would be to establish the QBFC connection only when it’s required and release it as soon as the operation is complete.
Another approach you can try is to close the previous connection during the application startup or before accquiring the new connection. If any kind of session identifier is involved, persist the same in a file and use that to close the connection.
Upvotes: 2