+ Reply to Thread
Results 1 to 6 of 6

Excel Process Hanging ( Interop.Excel)

  1. #1
    Jörgen Ahrens
    Guest

    Excel Process Hanging ( Interop.Excel)

    Hi All

    I have a probelm with Excel Automation. I create an Excel Application and
    open a workbook. Then I close the workbook and Quit the Excel Application,
    but the Excel.exe Process does not disapear...

    What am i doing wrong?

    Thanks
    j.ahrens

    My Code:

    using System;
    using System.Reflection;
    using Excel = Microsoft.Office.Interop.Excel;

    namespace TestApplication
    {
    /// <summary>
    /// Summary description for ExcelTest.
    /// </summary>
    public class ExcelTest
    {
    [STAThread]
    static void Main()
    {
    //my excel file
    string file = @"C:\Tmp\Test.xls";

    //Set culture to english-US, otherwise the interop won't work
    System.Threading.Thread.CurrentThread.CurrentCulture = new
    System.Globalization.CultureInfo("en-US");

    //Create the excel application
    Excel.ApplicationClass app = new
    Microsoft.Office.Interop.Excel.ApplicationClass();

    //Open the workbook
    Excel.Workbook wb = app.Workbooks.Open(file, false, true, Missing.Value,
    Missing.Value, Missing.Value,
    Missing.Value, Missing.Value, Missing.Value, Missing.Value,
    Missing.Value, Missing.Value, Missing.Value, Missing.Value,
    Missing.Value);

    //Close the workbook
    wb.Close(false, Missing.Value, Missing.Value);

    //Release the workbook com reference
    System.Runtime.InteropServices.Marshal.ReleaseComObject(wb);
    wb = null;

    //Close the excel application
    app.Quit();

    //Release the application com reference
    System.Runtime.InteropServices.Marshal.ReleaseComObject(app);
    app = null;

    System.Threading.Thread.Sleep(5000);
    GC.Collect();
    GC.WaitForPendingFinalizers();
    GC.Collect();
    GC.WaitForPendingFinalizers();
    }
    }
    }



  2. #2
    wav
    Guest

    RE: Excel Process Hanging ( Interop.Excel)

    try next code

    if (Marshal.IsComObject(app))
    {
    while (Marshal.ReleaseComObject(app) > 0) { };
    app = null;
    }
    GC.Collect();
    GC.WaitForPendingFinalizers();
    GC.Collect();

    GC.GetTotalMemory(true);
    GC.SuppressFinalize(this);

    instid
    System.Runtime.InteropServices.Marshal.ReleaseComObject(app);
    app = null;

  3. #3
    Jörgen Ahrens
    Guest

    Re: Excel Process Hanging ( Interop.Excel)

    The Process is still hanging...



  4. #4
    Peter Huang [MSFT]
    Guest

    Re: Excel Process Hanging ( Interop.Excel)

    Hi,

    What Excel version did you use?
    For Office XP amd 2003 we have special PIA(primary interop assembly), I
    suggest you install them first.

    Office XP PIAs
    http://www.microsoft.com/downloads/d...&familyid=c41b
    d61e-3060-4f71-a6b4-01feba508e52

    Office 2003 Update: Redistributable Primary Interop Assemblies
    http://www.microsoft.com/downloads/d...83A-AC14-4125-
    8BA0-D36D67E0F4AD&displaylang=en

    NOTE: Office 2003 PIA is also installed with Office 2003 installation
    program.

    Also please follow the KB below to see if that works for you.
    317109 Office application does not quit after automation from Visual Studio
    .NET client
    http://support.microsoft.com/default...b;EN-US;317109


    Best regards,

    Peter Huang

    Microsoft Online Community Support
    ==================================================
    When responding to posts, please "Reply to Group" via your newsreader so
    that others may learn and benefit from your issue.
    ==================================================
    This posting is provided "AS IS" with no warranties, and confers no rights.


  5. #5
    wav
    Guest

    RE: Excel Process Hanging ( Interop.Excel)

    you kill only first of your objects.
    type before release Excel app next

    if (Marshal.IsComObject(wb))
    {
    while (Marshal.ReleaseComObject(wb) > 0) { };
    wb = null;
    }

  6. #6
    Jörgen Ahrens
    Guest

    Re: Excel Process Hanging ( Interop.Excel)

    Thanks for your response.

    We found the problem...it was an excel add-in...that did not destroy itselfe
    properly. got to work that out.

    Thanks
    j.ahrens



+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1