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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T19:56:22+00:00 2026-06-18T19:56:22+00:00

Without using extra threads I would simply like to display a Loading label or

  • 0

Without using extra threads I would simply like to display a “Loading” label or something similar to the user when a large amount of data is being read or written. If I however attempt to modify any UI elements before calling the IO method, the application freezes for a while and then displays the “Loading” message after all the work is already done. This obviously doesn’t help. How can I ensure that any UI changes are applied and visible before calling the IO method?

        DataSet ds = STT_Import.ImportExcelToDataSet(filePath);

        bool result = false;

        if (ds != null)
        {
            int cellCount = ds.GetTotalCellCount();

            if (Popup.ShowMessage(string.Format("Your file contains {0} cells. Inserting data will take approximately {1} seconds. Do you want to continue?",
                cellCount, CalculateTime(cellCount)), "Confirm", MessageType.Confirm) == MessageBoxResult.Yes)
            {
                // Tell user the application is working:
                StatusLabel.Content = "Writing to database...";

                // Do actual work after user has been notified:
                result = DB.StoreItems(_currentType, ds);
            }
        }

I tried looking for answers but couldn’t find anything that answered my specific question, so I’m sorry if the question has been asked before.

  • 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-18T19:56:23+00:00Added an answer on June 18, 2026 at 7:56 pm

    When working with WPF, you can use the Dispatcher to queue commands on the UI thread at different DispatcherPriorities

    This will allow you to queue your long-running process on the UI thread after everything in the DispatcherPriority.Render or DispatcherPriority.Loaded queues have occurred.

    For example, your code may look like this:

    // Tell user the application is working:
    StatusLabel.Content = "Writing to database...";
    
    // Do actual work after user has been notified:
    Dispatcher.BeginInvoke(DispatcherPriority.Input,
        new Action(delegate() { 
            var result = DB.StoreItems(_currentType, ds);     // Do Work
            if (result)
                StatusLabel.Content = "Finished";
            else
                StatusLabel.Content = "An error has occured";
         }));
    

    It should be noted though that its usually considered bad design to lock up an application while something is running.

    A better solution would be to run the long-running process on a background thread, and simply disable your application form while it runs. There are many ways of doing this, but my personal preference is using the Task Parallel Library for it’s simplicity.

    As an example, your code to use a background thread would look something like this:

    using System.Threading.Tasks;
    
    ...
    
    // Tell user the application is working:
    StatusLabel.Content = "Writing to database...";
    MyWindow.IsEnabled = False;
    
    // Do actual work after user has been notified:
    Task.Factory.StartNew(() => DB.StoreItems(_currentType, ds))
        // This runs after background thread is finished executing
        .ContinueWith((e) =>
        {
            var isSuccessful = e.Result;
    
            if (isSuccessful)
                StatusLabel.Content = "Finished";
            else
                StatusLabel.Content = "An error has occured";
    
            MyWindow.Enabled = true;
        });
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want to do something like this without using extra variables: class className {
How would I convert a number from binary to base 4 without using extra
I'd like to create an infinite side scrolling div without using extra plugins (besides
Is there a way without using extra space to find LCA of nary tree.
I'm trying to bootstrap (a subset of) C from scratch, without using extra dependencies
I need to add some extra field to Joomla registration form without using any
How do I center list items inside a ul without using extra divs or
How to compress strings like aaabbbc to a3b3c and decompress the same, without using
When I run this without using the extra-escape for the \n , hexdump doesn't
Can threads have more than one argument without using a struct? So... kind of

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.