Using Wrapper objects to Properly clean up excel interop objects

前端 未结 5 1090
滥情空心
滥情空心 2021-02-20 02:39

All of these questions:

  • Excel 2007 Hangs When Closing via .NET
  • How to properly clean up Excel interop objects in C#
  • How to properly clean up inte
5条回答
  •  广开言路
    2021-02-20 03:21

    For what it's worth, the Excel Refresh Service on codeplex uses this logic:

        public static void UsingCOM(T reference, Action doThis) where T : class
        {
            if (reference == null) return;
            try
            {
                doThis(reference);
            }
            finally
            {
                Marshal.ReleaseComObject(reference);
            }
        }
    

提交回复
热议问题