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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T09:23:48+00:00 2026-06-08T09:23:48+00:00

I’m working on a C#/.NET 3.5/Windows Forms program. I would like to create a

  • 0

I’m working on a C#/.NET 3.5/Windows Forms program. I would like to create a Modeless Dialog box and then update it with information generated from the main form. I’ve found several examples of the other direction – info from a dialog box updates the main window, but I’m having trouble going in the reverse direction. The GUI in the dialog box just doesn’t function properly. The mouse cursor is an hourglass. I sometimes see updates, but I often see a solid white box, remnants of other windows that were once on top of the dialog box, or it freezes.

Eventually the Dialog box will display more complicated information, but for now I’m just trying to duplicate a counter that appears as a label on the Main Window. To launch the dialog, I do the following:

    bool secondWindowOpen = false;
    Thread secondWindowThread;
    MyPopupWindow secondWindow;

    delegate void TextBoxDelegate(string message);

    private void buttonPop_Click(object sender, EventArgs e)
    {
        // If the second window is not open, then open it
        if (!secondWindowOpen)
        {
            secondWindowOpen = true;

            secondWindow = new MyPopupWindow();
            secondWindowThread = new Thread(secondWindow.MyMethod);
            secondWindowThread.Start();

        }
        else // Close the second window
        {
            secondWindowOpen = false;
            secondWindow.ShouldStop = true;

            secondWindowThread.Join();                
        }
    }

I update the counter with the following code:

if (secondWindow != null)
{
    secondWindow.CounterText = args.FrameNumber.ToString();
}

The code for controlling the Modeless Dialog box looks like the following. I’ll admit the code for setting the text field is probably wrong, but it’s the best thing I have working at the moment (Invoke calls were giving me trouble).

public partial class MyPopupWindow : Form
{
    public MyPopupWindow()
    {
        InitializeComponent();
    }

    public bool ShouldStop
    {
        get { return shouldStop; }
        set { shouldStop = value; }
    }
    private bool shouldStop = false;

    public void MyMethod()
    {            
        this.Show();
        this.Refresh();

        while (!shouldStop)
        {
            Thread.Sleep(100);
            labelCounter.Text = CounterText;
            Refresh();
        }

        this.Close();
    }

    public string CounterText;
}

My big questions are the following: What is the best way to put a Modeless Dialog Box into a second thread when it just needs to update its own GUI elements? What is the best way to update those GUI elements from the Main Window/Thread? 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-06-08T09:23:49+00:00Added an answer on June 8, 2026 at 9:23 am

    The way forms work is that at the core if the program is a loop that processes messages and passes them out to the forms to be processed. If your form never returns control to your message loop, your program stops working properly. You’ve tried to solve this by adding more threads, but that way leads to pain of its own.

    You can’t do this in a thread as all operations applied to your form MUST be done on the UI thread.
    You could pass back calls like Invalidate to the UI thread using BeginInvoke, but that gets really messy – it’s much better to write cooperative windows that run on the one UI thread than to fire off lots of threads that then try to prod the UI thread into doing things for them.

    To do this you would create the form and then return control to your message handling loop. At a future time you would close the window from an event like a button click. If you need to update the window as result of any events, you would call invalidate in your event handler and then return.

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

Sidebar

Related Questions

I would like to count the length of a string with PHP. The string
I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
I would like to run a str_replace or preg_replace which looks for certain words
I would like my Web page http://www.gmarks.org/math_in_e-mail.txt on my Apache 2.2.14 server to display
link Im having trouble converting the html entites into html characters, (&# 8217;) i
For some reason, after submitting a string like this Jack’s Spindle from a text
Basically, what I'm trying to create is a page of div tags, each has
I've got a string that has curly quotes in it. I'd like to replace
I am trying to render a haml file in a javascript response like so:
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this

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.