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

  • Home
  • SEARCH
  • 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 6871347
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T03:47:41+00:00 2026-05-27T03:47:41+00:00

I have a a wait form FormWait (long running task notification), that has ShowMessage(string

  • 0

I have a a wait form FormWait (long running task notification), that has ShowMessage(string message) function.

Often happens in code:

public RootCall() 
{
   FormWait.ShowMessage("Begin long task 1..."); 

   ChildCall();

   FormWait.CloseForm();   
}

public ChildCall() 
{
   FormWait.ShowMessage("Begin long task 2..."); 

   // some code here

   FormWait.CloseForm();   
}

FormWait on root shows the message to the user, but before closing it on root level, there is another ShowMessage of child and CloseForm of child.

I have a couple of solutions to resolve this:

  1. Like in code provided the methods are static and operate on one static System.Windows.Forms.Form instance. On every ShowMessage there is a static variable that increments and on every CloseForm it decrements. So by looking on that variable I can understand if I really need to close the form (if I’m or not on root level), or its just a nested CloseForm call. And on every ShowMessage new string just updated on already visible form.

  2. For every new ShowMessage call create new instance of the form, but this is really wired to see. So almost sure I will not pick this solution.

Any ideas, how can I manage WaitForm (form that signals to user about long running tasks) in case of nested calls, by making also the developer life easier.?

  • 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-27T03:47:42+00:00Added an answer on May 27, 2026 at 3:47 am

    The Stack<> class is the natural fit for this:

    public partial class WaitForm : Form {
        private WaitForm() {
            InitializeComponent();
        }
        private static WaitForm instance;
        private static Stack<string> messages = new Stack<string>();
    
        public static void ShowMessage(string message) {
            if (instance == null) {
                instance = new WaitForm();
                instance.FormClosed += delegate { instance = null; };
                instance.Show();
            }
            messages.Push(message);
            instance.lblMessage.Text = message;
            instance.Update();
        }
    
        public static void CloseForm() {
            messages.Pop();
            if (instance != null) {
                if (messages.Count == 0) instance.Close();
                else instance.lblMessage.Text = messages.Peek();
            }
        }
    }
    

    Don’t forget to put the CloseForm() call in a finally block so this is all exception safe.

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

Sidebar

Related Questions

I have this ajax function: function callpage() { $('#formcontent').empty().html('<p class=vent>Pleace wait</p>'); var form =
I have few asynchronous tasks running and I need to wait until at least
I have a thread that does the following: 1) Do some work 2) Wait
I have a custom thread pool class, that creates some threads that each wait
I have a form that needs to run a php script once the submit
I have a form that i am trying to submit after the page loads
We have a form with five <input type=file/> elements that is in production and
I have these three images that I have drawn to my form. GraphicsBuffer.DrawImage(ButtonEasy, New
I have a form that spawns a BackgroundWorker, that should update form's own textbox
I have a form that validates using the jQuery plugin: Validation, v1.9.0. The validation

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.