rcw

Can't get all excel processes to stop when closing through Powershell

时光总嘲笑我的痴心妄想 提交于 2019-11-30 22:54:10
With this code, I am opening excel(with visible = false so the user cannot see it), writing to a workbook, and then either opening excel(making it visible) after the script ends or closing it completely without saving. When I save excel, leave it open, end the script, and then manually close excel later, there are no background processes in the task manager. However, when I close excel with the script, it remains in the task manager. Here is how I start excel: $script:excel = new-object -ComObject excel.application # create excel object $excel.visible = $false # hide excel window $script

Can't get all excel processes to stop when closing through Powershell

馋奶兔 提交于 2019-11-30 17:33:53
问题 With this code, I am opening excel(with visible = false so the user cannot see it), writing to a workbook, and then either opening excel(making it visible) after the script ends or closing it completely without saving. When I save excel, leave it open, end the script, and then manually close excel later, there are no background processes in the task manager. However, when I close excel with the script, it remains in the task manager. Here is how I start excel: $script:excel = new-object

RCW & reference counting when using COM interop in C#

谁说我不能喝 提交于 2019-11-27 18:02:16
I have an application that uses Office interop assemblies. I am aware about the "Runtime Callable Wrapper (RCW)" managed by the runtime. But I am not very sure how the reference count gets incremented. MSDN says, RCW keeps just one reference to the wrapped COM object regardless of the number of managed clients calling it. If I understand it correctly, on the following example, using Microsoft.Office.Interop.Word; static void Foo(Application wrd) { /* .... */ } static void Main(string[] args) { var wrd = new Application(); Foo(wrd); /* .... */ } I am passing the instance wrd to another method.