Home
Forums
New posts
Search forums
Articles
Latest reviews
Search resources
Members
Current visitors
Newsgroups
Log in
Register
What's new
Search
Search
Search titles only
By:
New posts
Search forums
Menu
Log in
Register
Install the app
Install
Home
Forums
Newsgroups
Microsoft DotNet
Microsoft VB .NET
Wrapping Word.Application object with an IDisposable class?
JavaScript is disabled. For a better experience, please enable JavaScript in your browser before proceeding.
You are using an out of date browser. It may not display this or other websites correctly.
You should upgrade or use an
alternative browser
.
Reply to thread
Message
[QUOTE="Jialiang Ge [MSFT], post: 11132982"] Hello, From your post, my understanding on this issue is: you want to know why the Word process is not closed in Dispose method when the application is tested in Visual Studio debug mode. If I'm off base, please feel free to let me know. I did a test with your WordFactory class. In order to see why the Word process is not closed in Dispose, I removed the "On Error Resume Next" and "On Error GoTo 0" around "mobjWordApp.Quit()", then I got the exception thrown by Visual Studio debugger at the sentence: *COM object that has been separated from its underlying RCW cannot be used.* This problem is most likely caused that your COM objects are called on different threads. The creation of the COM object is on one thread (the main thread in this issue), and the clean on another thread (the .NET Garbage Collection thread in this context). By default we use STA apartment model so if you are using COM objects in different threads, this may cause issues like interop exceptions "object disconnected from its RCW". It means that we need to keep track of the thread which created those COM objects. If that thread ends, the COM object will also go away even if the RCW that ..NET is using is still alive because the GC has not cleaned it yet (Dispose has not been called). In your question, you said that the problem only occurs in VS IDE, but based on my test, sometimes the exception also occurs when I run the application directly. In order to resolve the problem, I still suggest that you call mobjWordApp.Quit in the thread where wobjWordApp is created because Office COM object is designed as STA. Please also call System.Runtime.InteropServices.Marshal.ReleaseComObject to ensure all the reference count to the COM object is decreased. (See the kb article Office application does not quit after automation from Visual Studio .NET client [URL]http://support.microsoft.com/kb/317109[/URL]). Please let me know if you have any other concerns, or need anything else. Sincerely, Jialiang Ge (jialge@online.microsoft.com, remove 'online.') Microsoft Online Community Support ================================================== For MSDN subscribers whose posts are left unanswered, please check this document: [URL]http://blogs.msdn.com/msdnts/pages/postingAlias.aspx[/URL] Get notification to my posts through email? Please refer to [URL]http://msdn.microsoft.com/subscriptions/managednewsgroups/default.aspx#notif[/URL] ications. If you are using Outlook Express/Windows Mail, please make sure you clear the check box "Tools/Options/Read: Get 300 headers at a time" to see your reply promptly. Note: The MSDN Managed Newsgroup support offering is for non-urgent issues where an initial response from the community or a Microsoft Support Engineer within 1 business day is acceptable. Please note that each follow up response may take approximately 2 business days as the support professional working with you may need further investigation to reach the most efficient resolution. The offering is not appropriate for situations that require urgent, real-time or phone-based interactions or complex project analysis and dump analysis issues. Issues of this nature are best handled working with a dedicated Microsoft Support Engineer by contacting Microsoft Customer Support Services (CSS) at [URL]http://msdn.microsoft.com/subscriptions/support/default.aspx[/URL]. ================================================== This posting is provided "AS IS" with no warranties, and confers no rights. [/QUOTE]
Verification
Post reply
Home
Forums
Newsgroups
Microsoft DotNet
Microsoft VB .NET
Wrapping Word.Application object with an IDisposable class?
Top