开发者

Is calling Marshal.ReleaseComObject necessary if the process is terminating?

开发者 https://www.devze.com 2023-03-17 04:08 出处:网络
I have a console application that automates another windows application through COM interop. It automates the app开发者_JAVA技巧lication to open a file, take a screen shot and then exits.

I have a console application that automates another windows application through COM interop. It automates the app开发者_JAVA技巧lication to open a file, take a screen shot and then exits.

I was wondering if there would be any ill effects if I didn't call Marshall.ReleaseComObject on the limited number of com objects that are getting instantiated? It seems cleaner to call the release method to clean up the objects but is it really necessary in this case?


Is it necessary? Probably not. But if you don't, I can almost guarantee that at some point this will come back and bite you. Whenever I'm using an unwrapped COM object, I always wrap it in a try...finally block and perform a ReleaseComObject in the finally.

0

精彩评论

暂无评论...
验证码 换一张
取 消