DisposableAction and Marshal.ReleaseComObject

performing some Interop operations and the code is of type

            try
            {
                selection = getSelected(Return.Some.Office.InteropObject);
                for ( int i = 0 ; i < selection.count ; i++)
                    yield return selection.item(i)
            }
            finally
            {
                Marshal.ReleaseComObject(selection);
            }

      

Wondering if this is a good idea, replace it with DisposableAction and change to

         using ( var a = new DisposableAction(getSelected(Return.Some.Office.InteropObject)) )
         {
              foreach(var b in a.Items)
                yield return b;
         }

      

+3
c # .net interop office-interop com


source to share


No one has answered this question yet

See similar questions:

2
How to return IEnumerable <T> for one element

or similar:

406
Using var keyword in C #
64
Excel interop: desktop or worksheet?
32
Why use FinalReleaseComObject instead of ReleaseComObject?
eleven
Using Wrapper objects to properly clean up interc interel objects
five
Working with a managed COM object from unmanaged code
4
Adding html text to Word using Interop
1
C # Com Interop Marshalling for Arrays
0
Replace a range of bookmarks in a Word document with formatted (HTML) text
0
Why does SAPbobsCOM.dll in SAP b1 need to set "embed interop types" to false?
0
.net, cast class as subclass



All Articles
Loading...
X
Show
Funny
Dev
Pics