none
How to close the background excel instance when i close the console application abruptly RRS feed

  • Question

  • I have a console application which does some operations on the data in the excel file and adds data of the calculation results in a new sheet. Now during the processing when i close the console app, the excel instance which is running in the background is not close. My console app takes user input during the processing. I'm using  "Microsoft.Office.Interop.Excel". 

    i have this code which is executed only if I finish the entire processing and closes the excel instance. But if i close the application in the middle the excel instance is not closed. 

    finally {
                    app.Quit();
                    Marshal.FinalReleaseComObject(app);
                }

    What should be my approach to close the excel instance when a user clicks the X of the command prompt? 


    karteek_paruchuri

    Monday, January 6, 2014 5:29 AM

Answers

  • Hi karteek,

    According to your description, you want to know how to catch close event of a console application.

    The question is not related to the topic of our forum. I would recommend you to get more effective from Visual C#.

    In addition, I found a possible solution from another post: C# Console Application Closing Event.

    You can try to call Windows API to catch close event then close the Excel instance.

    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.

    • Proposed as answer by Kelmen Tuesday, January 7, 2014 6:29 AM
    • Unproposed as answer by karteek paruchuri Tuesday, January 7, 2014 9:44 AM
    • Marked as answer by karteek paruchuri Tuesday, January 7, 2014 9:44 AM
    Tuesday, January 7, 2014 6:26 AM
    Moderator

All replies

  • Hi karteek,

    According to your description, you want to know how to catch close event of a console application.

    The question is not related to the topic of our forum. I would recommend you to get more effective from Visual C#.

    In addition, I found a possible solution from another post: C# Console Application Closing Event.

    You can try to call Windows API to catch close event then close the Excel instance.

    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.

    • Proposed as answer by Kelmen Tuesday, January 7, 2014 6:29 AM
    • Unproposed as answer by karteek paruchuri Tuesday, January 7, 2014 9:44 AM
    • Marked as answer by karteek paruchuri Tuesday, January 7, 2014 9:44 AM
    Tuesday, January 7, 2014 6:26 AM
    Moderator
  • In the hyperlink you pointed to http://geekswithblogs.net/mrnat/archive/2004/09/23/11594.aspx, the console application close event handler is not releasing my excel object. I read on the web saying that these event handling will have a 3 second window to perform our actions which I'm unable to do in my case. Can you give more insight on this 3 second concept ?

    karteek_paruchuri

    Tuesday, January 7, 2014 9:46 AM