Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8222417
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T14:16:21+00:00 2026-06-07T14:16:21+00:00

This is in continuation to my previous question ( Open Excel Workbook with vba

  • 0

This is in continuation to my previous question (Open Excel Workbook with vba code – error to notify VSTO) which is yet to be resolved. I have a fresh set of problem with Excel Interop.
Even without any error in the excel file I see that workBooks.Open sometimes hangs indefinitely thus causing my application to hang forever. I am using the following code to initialize the excel object

    public static class InterOpService
    {
            private static Application _excel;


            public static Application Excel
            {
                get
                {
                    try
                    {
                        _excel = (Application)System.Runtime.InteropServices.Marshal.GetActiveObject("Excel.Application");
                        _excel.Visible = true;
                    }
                    catch(Exception ex)
                    {

                        _excel = new Application { Visible = true };
                    }
                    return _excel;
                }
            }
     }

The above code returns me an Excel object. It also tries to avoid creating multiple instances of Excel object. The following code uses this returned object

Application excel = InterOpService.Excel;
Workbooks workBooks = excel.Workbooks;
string file  = fileName;
Workbook workBook = workBooks.Open(file, 0,
                                      true,
                                      5,
                                      "",
                                      "",
                                      true,
                                      XlPlatform.xlWindows,
                                      "\t",
                                      false,
                                      false,
                                      0,
                                      true,
                                      1,
                                      0);

One probable reason I see to thi hanging of workbooks.open is file sharing. Probably an antivirus scanner is getting the exclusive lock onto the file and my app is hanging while trying to Open at that time. The problem is this is a random behavior and I am really struggling to replicate this.Another problem is I have to find a way out with Interop only.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-07T14:16:24+00:00Added an answer on June 7, 2026 at 2:16 pm

    I found the issue.
    Following were the reasons for hanging:

    1) I was opening the workbook over the network.

    Workbook workBook = workBooks.Open(file, 0,
                                      true,
                                      5,
                                      "",
                                      "",
                                      true,
                                      XlPlatform.xlWindows,
                                      "\t",
                                      false,
                                      false,
                                      0,
                                      true,
                                      1,
                                      0);
    

    file was not in my local machine. The number of cases with hanging reduced after I copied the file to local machine and did the open.

    2) Server memory.
    Another reason for hanging was that the CPU usage in the server was 100%.Not in my control. But satisfied that I hunted this down.

    The main problem with Open method is that it is not responsive enough to let the caller know about these reasons. The best way is, to do this activity in a thread and give the thread sometime to execute. Fail, if the thread does not respond in the specified time frame.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

This is in continuation to my previous question which was closed cause of similarity
This is a continuation of my previous question which I posted when I wasn't
This question is in continuation to my previous question, in which I asked about
This is a continuation of my previous question .NET regex engine returns no matches
This question is a continuation of my previous question here zend models architecture (big
This question is in continuation to my previous question . I am trying to
This is a continuation from a previous stackoverflow question. I've renamed some variables so
This question is a continuation of a previous thread to compare two lists with
This is a continuation of my previous question: Could not find an implementation of
This question is in continuation to my previous post located here . Since there

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.