Ahsan Alii Ahsan Alii - 4 months ago 33
C# Question

How to make C# application responsive

I'm working on an application which have a huge loop for a calculation, the problem is i want the label text to be continuously updated i.e how many rows are updated ? I've a counter variable in a loop and

statement ? but it only changes once after the end of loop, I want it to be updated after every iteration ?
What should be done for this issue ? Do I have to use threads ?


This answer will be somewhat vague unless you post more information on what your target app is (WPF, ASP.net, WinForms, etc), and some code examples of what you are currently doing.

Regardless, you'll want to try and leverage your UI framework to do the control updating, versus doing it manually yourself.

For example, if your app UI is WPF, you can leverage data binding by binding to a property on a view model (or in the code-behind) that implements the INotifyPropertyChanged interface.

This way, the control bound to the property (for example, a label or textbox) will update automatically whenever the property value is changed by the view model, so you can concentrate on the business logic instead of attempting to manually update the UI yourself.