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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T17:19:59+00:00 2026-05-15T17:19:59+00:00

I have a very annoying problem and I’m trying to find the simplest solution

  • 0

I have a very annoying problem and I’m trying to find the simplest solution possible, but I seem to keep complicating it.

My program displays a custom dialog box using the ShowDialog function (I create this form using a New constructor), but while my program waits for input in the dialogbox, my program continues to run other code, (I’m assuming initiated from other messages, but I still can’t find good information on this, so as an aside to this topic does anyone have a reference about this), and arrives at this same point where the dialog box is to be displayed and displays it. So I end up getting a flood of dialog boxes.

My goal is prevent this excessive amount of dialog boxes. If the program arrives at this dialog initiation point I would like it to wait/pause until the first dialog box is finished.

I thought about threaded solutions, background workers, all kinds of ideas but they just seem to complicate things and I haven’t actually fixed it.

Does anyone have an idea how I could prevent this from occurring?

Your help is greatly appreciate.
Thanks

  • 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-15T17:20:00+00:00Added an answer on May 15, 2026 at 5:20 pm

    It seems to me that you have some very ugly bug in your code! I’d focus on fixing this bug first. The easy way to do this is to set a breakpoint on the line that opens up the dialog. When the line is hit the second time (while the first dialog box is still open), view the stacktrace at that point and check all active threads (View Threads and View Stack windows) for the cause of the issue.

    In addition, change your code to open a modal dialog window instead, where the parent window must be the owner. A modal dialog window will stop execution and prevent the parent window from processing user input (which could’ve lead to this behavior).

    Edit

    From your comments I gather that you have several threads that you cannot control and that you want one thread at a time to access the messagebox code. When working with threads, there are several synchronisation primitives available. Expanding on each of them requires a book (you may try Concurrent Programming on Windows, one that’s thorough while the book has some flaws in its structure), knowing the right one for you requires knowledge of your code.

    That said, you may wish to do something like the following, using a Mutex which at least prevents other threads to access the code (meaning: it will put them in a suspend state until the Mutex is released). Add a static boolean flag variable (or add a checkbox on the popupped form “show box only once”) if you want to prevent the popup box to show more than once. Mutex plus flag solves two problems in one: only one thread will ever run that code, and the code will only run once, ever.

    // as static class variable, create a mutex
    private static Mutex dialogMutex = new Mutex();
    
    // a static flag preventing the dialog box to show more than once
    // (you may wish to resolve this differently, depending on req's)
    private static boolean dialogIsShownOnce = false;
    
    public static void ShowDialogBox()
    {
        // Wait until it is safe to enter, this makes the current thread 
        // the exclusive user of this code and other threads may only enter
        // after the current thread finishes.
        dialogMutex.WaitOne();
    
        // depending on your requirements, you may not want this
        // must come _after_ WaitOne to prevent entering before another
        // thread that entered hasn't yet changed this variable
        if(dialogIsShownOnce)
           return;
    
    
        // show your dialog box as a modal box 
        // if you are unsure: add a breakpoint just after the ShowDialog 
        // it should only be hit _after_ you dismiss the dialog box
        yourForm.ShowDialog();
    
        // set the flag, or the counter, or whatever you wish:
        dialogIsShownOnce = true;
    
        // Release the Mutex, this will remove the "roadblock" and allow
        // other threads to enter this piece of code
        dialogMutex.ReleaseMutex();
    }
    

    The code above is not tested and should be considered a hint on how to tackle this issue. There are so many ways to solve this, but I think the above method may just be what you need.

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

Sidebar

Related Questions

I have a layout that is working, but it has one very annoying problem..
I've recently started using GNU Screen but have run into a very annoying problem.
I have a very simple problem which requires a very quick and simple solution
I have a very annoying problem with LINQ and MS SQL Server. Im currently
I have a very annoying problem: My project (JSP, Servlet) requires Xerces-J 2.8.1 or
I've got a very annoying problem with my Zend studio. I have a zend
We've got this very annoying problem with Scriptaculous and Internet Explorer 7/8. We have
Hey there, i got this very annoying problem: I have a CheckBoxList getting items
I have somehow misconfigured fingers. This leads to a very annoying situation. I select
We have very strange problem, one of our applications is continually querying server by

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.