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 6854119
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T01:35:39+00:00 2026-05-27T01:35:39+00:00

protected override void OnBeforeInstall(IDictionary savedState) { base.OnBeforeInstall(savedState); DialogResult result = DialogResult.None; if (isExcelIsRunning()) {

  • 0
protected override void OnBeforeInstall(IDictionary savedState)
{
    base.OnBeforeInstall(savedState);
    DialogResult result = DialogResult.None;
    if (isExcelIsRunning())
    {
        result = MessageBox.Show("Excel is still running. Please save your work and close Excel, and then click \"Retry\" button to continue with installation.", "", MessageBoxButtons.RetryCancel, MessageBoxIcon.Warning);
    }
    while (result == DialogResult.Retry)
    {
        if (!isExcelIsRunning())
        {
            break;
        }
    }
}


//check if excel is currently running
private bool isExcelIsRunning()
{
    bool flag = false;
    Process[] xlProc = Process.GetProcessesByName("excel");
    if (xlProc != null)
        flag = true;
    return flag;
}

The above is the code I am about to use for my Installer Class.

What I want to achieve here is that I need the installer to check whether or not Excel is currently running during the installation. And if it is running, then there should be a pop-up message at the start of installation to alert user to close off Excel and the installer should pause until there’s no Excel instance found in the process list any more.

Back to the code, I don’t think that while block is quite right, as it could cause an endless loop after user clicks “Retry” button if in the mean time Excel is still running.

So what’d be the better approach? Would anyone here take a look at the above code and see where I can improve?

  • 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-05-27T01:35:39+00:00Added an answer on May 27, 2026 at 1:35 am

    I think your code would be something like this:

    while(isExcelRunning())
    {
        var result = MessageBox.Show("Excel is still running. Please save your work and close Excel, and then click \"Retry\" button to continue with installation.", "", MessageBoxButtons.RetryCancel, MessageBoxIcon.Warning);
        if (result != DialogResult.Retry)
        {
             //Handle Cancel
             break;
        }
    }
    

    This will keep displaying the alert in a loop, either until Excel exits, or they press cancel, at which you can do whatever you need to do; then we exit the loop (or you could return entirely out of the method).

    The key here is display the alert repetitively, either until Excel is gone or they choose to cancel. If you need to do some code after the loop based on the response; perhaps something like this:

    var userHasCancelled = false;
    while(!userHasCancelled && isExcelRunning())
    {
        var result = MessageBox.Show("Excel is still running. Please save your work and close Excel, and then click \"Retry\" button to continue with installation.", "", MessageBoxButtons.RetryCancel, MessageBoxIcon.Warning);
        if (result != DialogResult.Retry)
        {
             userHasCancelled = true;
        }
    }
    if (userHasCancelled)
    {
        //User cancelled...
    }
    else
    {
        //Continue.
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

i found this code: protected override void OnSourceInitialized(EventArgs e) { base.OnSourceInitialized(e); HwndSource hwndSource =
My base controller has this override: protected override void OnException(ExceptionContext filterContext) { // http://forums.asp.net/t/1318736.aspx
I understand basic AXML usage such as: protected override void OnCreate(Bundle bundle) { base.OnCreate(bundle);
public class Boards : TabActivity { protected override void OnCreate(Bundle bundle) { base.OnCreate(bundle); SetContentView(Resource.Layout.Tab);
I have overridden this method: protected override void OnBackKeyPress(System.ComponentModel.CancelEventArgs e) { base.OnBackKeyPress(e); IAsyncResult guide
Why doesn't it work? i got this protected override void OnNavigatedTo(System.Windows.Navigation.NavigationEventArgs e) { base.OnNavigatedTo(e);
protected override void OnRenderFrame(FrameEventArgs e) { base.OnRenderFrame(e); GL.Clear(ClearBufferMask.ColorBufferBit | ClearBufferMask.DepthBufferBit); Matrix4 modelview = Matrix4.LookAt(0,
When I redirect like this way protected override void OnActionExecuting(ActionExecutingContext filterContext) { filterContext.Result =
I have a user control that has the following overridden event: protected override void
In my code behind I wire up my events like so: protected override void

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.