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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T00:56:42+00:00 2026-05-25T00:56:42+00:00

I have a MessageBox.Show event that I want to also prevents timer-based methods from

  • 0

I have a MessageBox.Show event that I want to also prevents timer-based methods from running while the MessageBox remains open.

Here is my code (Changes the value in a file location on a network every x minutes):

public void offlineSetTurn()
{
    try
    {
        using (StreamWriter sWriter = new StreamWriter("FileLocation"))
        {
            sWriter.WriteLine(Variable);
        }
    }
    catch (Exception ex)
    {
        DialogResult result = MessageBox.Show("Can't find file.  Click Okay to try again and Cancel to kill program",MessageBoxButtons.OKCancel);

        if (result == DialogResult.OK)
        {
            offlineSetTurn();
        }
        else if (result == DialogResult.Cancel)
        {
            Application.Exit();
        }
    }
}

I have methods in the form that are calling this every thirty seconds. Meaning every thirty seconds, another MessageBox pops up. Is there a way to pause the application with MessageBox and if not, what would be the best way to resolve this issue? If possible, I’d like to avoid using Timer.Stop() as it would reset the Timer count.

  • 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-25T00:56:43+00:00Added an answer on May 25, 2026 at 12:56 am

    The simplest solution is to have a flag indicating whether or not the message box is currently open:

    private bool isMessageBoxOpen = false;
    
    public void offlineSetTurn()
    {
        if (isMessageBoxOpen)
            return;
    
        try
        {
            using (StreamWriter sWriter = new StreamWriter("FileLocation"))
            {
                sWriter.WriteLine(Variable);
            }
        }
        catch (Exception ex)
        {
            isMessageBoxOpen = true;
            DialogResult result = MessageBox.Show("Can't find file.  Click Okay to try again and Cancel to kill program",MessageBoxButtons.OKCancel);
            isMessageBoxOpen = false;
    
            if (result == DialogResult.OK)
            {
                offlineSetTurn();
            }
            else if (result == DialogResult.Cancel)
            {
                Application.Exit();
            }
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Is there any way to have a default MessageBox.Show() caption? Let says I would
I have an MDI application. When I show a message box using MessageBox.Show(), the
I have a file called hellowf.cs class MyFirstApp { static void Main() { System.Windows.Forms.MessageBox.Show(Hello,
I have been using win32api.MessageBox to do alerts, and this works for apps running
I have a form in a Windows form application that I want to display
I have an application that has a main form and uses an event handler
I have a child form that is throwing an ApplicationException in the Load event
I have an application that reads from a COM Port and then does something
I have two buttons in my program and i want that when i press
I have 2 event handlers attached to buttons on the same form. I want

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.