Show a Progress Dialog Bar While Loading Data (WinForms and WPF)

Show a Progress Dialog Bar While Loading Data (WinForms and WPF)

This post shows how to display a progress bar while asynchronously loading data, and shows the different types of progress bars available.

When you're designing your application, you need to consider how to handle data loading in order to ensure the application always remains responsive to the user. Generally this is done by loading data asynchronously on a background thread, while the user may continue to interact with the application.

The issue is that without proper visualization, the user may wonder whether anything is happening. This leads to the use of a progress bar to indicate that some activity is being executed in the background.

Once the data has been loaded the progress bar should be hidden and the relevant controls to display the data should be shown.

Show Progress Dialog While Loading Data

Let's walk through with a few examples working with progress bars in WinForms and WPF.

Indeterminate Progress Bars

The first step is to asynchronously load your data so that the application UI remains responsive during longer-than-usual load times. This is handled pretty easily in .NET using an awaited method call. It means that any code that happens after the await, will not run until the operation is complete. It’s the easiest solution as shown below.

private async Task LoadData()
{
        // show progress bar
        progressBar1.Visible = true;
        await LoadDataAsync();
        // hide progress bar
        progressBar1.Visible = false;
}

All you have to do is set the progress bar visibility before you await the loading of data, and then set it invisible when the operation is complete. This works well if the progress bar is “indeterminate”, which means it will keep looping through the loading animation indefinitely until you stop it.

It’s a common design paradigm today to display an indeterminate progress bar, or ring, as data is loading. This is popular because with unpredictable networks we don’t know exactly how long it may take. The server we are calling may not be capable or willing to inform us how long it will take either.

To create an indeterminate progress bar in WinForms, set its Style property to Marquee. In WPF, set its IsIndeterminate property to True.

.net wpf winforms

Bootstrap 5 Complete Course with Examples

Bootstrap 5 Tutorial - Bootstrap 5 Crash Course for Beginners

Nest.JS Tutorial for Beginners

Hello Vue 3: A First Look at Vue 3 and the Composition API

Building a simple Applications with Vue 3

Deno Crash Course: Explore Deno and Create a full REST API with Deno

How to Build a Real-time Chat App with Deno and WebSockets

Convert HTML to Markdown Online

HTML entity encoder decoder Online

jQuery Ajax CRUD in ASP.NET Core MVC with Modal Popup

In this article, we’ll discuss how to use jQuery Ajax for ASP.NET Core MVC CRUD Operations using Bootstrap Modal. With jQuery Ajax, we can make HTTP request to controller action methods without reloading the entire page, like a single page application.

WPF and WinForms Will Run on .NET Core 3

If you haven't had a chance to explore the new capabilities of .NET Core 3, read along with an expert in the framework to discover what it brings to the table.

Bring the best of the Web to your .NET desktop applications with WebView2

This blog post was written together with Palak Goel, Program Manager on Edge Product Development team. Last year at Build, we introduced WebView2, a browser control that renders web content (HTML / CSS / JavaScript) with the new Chromium-based Microsoft Edge.

ML.NET Model Builder is now a part of Visual Studio | .NET Blog

ML.NET is a cross-platform, machine learning framework for .NET developers. Model Builder is the UI tooling in Visual Studio that uses Automated Machine Learning (AutoML) to train and consume custom ML.NET models in your .NET apps. You can use ML.NET and Model Builder to create custom machine learning models without having prior machine learning experience and without leaving the .NET ecosystem.

Hire ASP.Net Developers

Looking to outsource your asp dot net development requirement? ASP.Net is a special feature of the DOT Net framework created by Microsoft. At [HourlyDeveloper.io](https://hourlydeveloper.io/ "HourlyDeveloper.io"), we have a team of experienced...