Report progress in a task in C sharp

One of my first questions starting programming in Visual Studio WPF was how to run processes without freezing the GUI.

After learning the basic concepts of backgroundworkers and tasks in c sharp programming I wanted to know how to report task progress while the task was not yet finished.

I found all kind of solutions to update a progress bar. I also found solutions to use the result for a specific task.

Think still missing for me was to get a screen to show task progress, with detailed logging while the task was still running. In the end this article helped me finding a solution:

To implement this logic in a solution I needed I created a form and added a button and a listbox.

The button got the following implementation:

private async void ButtonAsyncFileProcessing_Click(object sender, RoutedEventArgs e)
var progressIndicator = new Progress(ReportProgress);
await MyMethodAsync(progressIndicator);

For the progress indicator I added the following class:

public class MyTaskProgress
//current progress
public int CurrentProgressAmount { get; set; }
//total progress
public int TotalProgressAmount { get; set; }
//some message to pass to the UI of current progress
public List CurrentProgressLogging { get; set; }

The async method I used for testing was this:

async Task MyMethodAsync(IProgress progress)
int sleepTime = 1000;
int totalAmount = 10000;
List log = new List();

for (int i = 0; i <= totalAmount;)
await Task.Delay(sleepTime);
log.Add(string.Format("On {0} Message", i));
progress.Report(new MyTaskProgress
CurrentProgressAmount = i, TotalProgressAmount = totalAmount, CurrentProgressLogging = log });
i = i + sleepTime;

The ReportProgress method used in the button click progressIndicator:

private void ReportProgress(MyTaskProgress progress)
string.Format("{0} out of {1}",

And this last method calls a UpdateScreen method:

private void UpdateScreen(List info, string status)
foreach (string s in info)
buttonAsyncFileProcessing.Content = "AsyncFileProcessing" +
"\n" + status;

The article that helped me understanding Tasks and backgroundworkers is: