How to close outlook after automating it in c#

前端 未结 1 1949

I am creating a program which converts Msg outlook file into pdf. What I did was export the Msg file into Html then convert the Html output to pdf. This is my code:

1条回答
  •  执笔经年
    2021-01-15 02:04

    The issue is that the outlook com object is holding on to references and stopping the app from closing. Use the following function and pass your "app" object to it:

    private void ReleaseObj(object obj)
    {
        try 
        {
            System.Runtime.InteropServices.Marshal.ReleaseComObject(obj);
        }
        catch {}
        finally 
        {
            obj = null;
        }
    }
    

    See https://blogs.msdn.microsoft.com/deva/2010/01/07/best-practices-how-to-quit-outlook-application-after-automation-from-visual-studio-net-client/

    0 讨论(0)
提交回复
热议问题