DisposableAction and Marshal.ReleaseComObject

北战南征 提交于 2019-12-10 19:09:57

问题


doing some office Interop 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 it's a good idea to replace it with a DisposableAction and change to

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

来源:https://stackoverflow.com/questions/9696115/disposableaction-and-marshal-releasecomobject

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!