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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 21, 20262026-05-21T08:45:43+00:00 2026-05-21T08:45:43+00:00

In a legacy app we have a single winform that locks up while executing

  • 0

In a legacy app we have a single winform that locks up while executing code on a button click…well it doesn’t lock up it just “stops responding” until the code executes.

What is the best (least amount of code and working) way to wrap the code below into a separate thread and show a loading window (frmLoading) while it executes? I know this should be relatively simple, but I have tried a few different things that haven’t quite worked out.

private void btnSynch_Click(object sender, EventArgs e)
{
    btnSynch.Enabled = false;

    if(chkDBSynch.Checked)
        PerformDBSyncronization();

    if(chkAppSynch.Checked)
        PerformApplicationSyncronization();

    btnSynch.Enabled = true;
}

EDIT:
Ok, I should have mentioned have tried backgroundworker, but I figured out where I was tripping up….This code would execute and the loading form was getting thrown behind the main form which is why I thought it wasn’t working. Can Anyone tell me how to prevent this from happening?

  private void btnSynch_Click(object sender, EventArgs e)
    {

        btnSynch.Enabled = false;
        frmLoading loadingWindow = new frmLoading();
        loadingWindow.Show();

        BackgroundWorker bw = new BackgroundWorker();
        bw.DoWork += (s, args) =>
        {

            Thread.Sleep(6000); //TODO:just for testing 
            if(chkDBSynch.Checked)
            PerformDBSyncronization();

            if(chkAppSynch.Checked)
            PerformApplicationSyncronization();
        };
        bw.RunWorkerCompleted += (s, args) =>
        {
            loadingWindow.Close();
        };
        bw.RunWorkerAsync();

        btnSynch.Enabled = true;
    }
  • 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-21T08:45:43+00:00Added an answer on May 21, 2026 at 8:45 am

    I feel silly…The loading form was popping up behind the the main form which is why I thought it wasn’t opening. I set the TopMost property to true and everything works as expected.

    Edit:
    Here is a good explanation why my form was popping up behind my window, I just wasn’t expecting the thread that was opening the window to not use the main form as the owner.

    Why use a owner window in MessageBox.Show?

    I ended up with my code looking like

            frmLoading loadingWindow = new frmLoading();
            loadingWindow.Show(this);
    
            BackgroundWorker bw = new BackgroundWorker();
            bw.DoWork += (s, args) =>
            {
                this.Invoke(new MethodInvoker(() => this.Enabled = false));
    
                if(chkDBSynch.Checked)
                PerformDBSyncronization();
    
                if(chkAppSynch.Checked)
                PerformApplicationSyncronization();
            };
            bw.RunWorkerCompleted += (s, args) =>
            {
                loadingWindow.Close();
                this.Invoke(new MethodInvoker(() => this.Enabled = true));
    
            };
    
            bw.RunWorkerAsync();
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have an MFC legacy app that I help to maintain. I'm not quite
We've got an app with some legacy printer setup code that we are still
My situation is I have a legacy app which I don't have the code
I have an unconventional legacy asp.net 1.1 web app that uses the src attribute
I have a legacy WinForms Mdi App in VB.Net 2.0 which I am adding
I inherited this gigantic legacy Java web app using Struts 1.2.4. I have a
I inherited this gigantic legacy Java web app using Struts 1.2.4. I have a
We have a large legacy VB app made up of a number of DLLs
I've got two legacy codebases that I would like to have living side by
The legacy web app I have inherited, which was custom-written for Oxfam New Zealand

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.