In my c# winform app I have a button which when clicked, it performs some calculations which can tke some time.
I also have a label.visible = false which I would like to label.visible = true right after the button click so that the user can see the app working away.
The thing is even when label.visible = true is the first thing in the button1_Click(object sender, EventArgs e) method, it only toggles to visible at the very end, after the calculation is performed.
How can I show the label right after the button_click?
There are several ways to tackle this.
One way (the simplest) is to call
right after you set the Label to visible.
Another is to do your calculations in a background thread. The easiest way to do that is to use a
BackgroundWorker. Then your main thread can just continue serving the UI (refreshing the form, responding to buttons etc.) while the background worker thread performs the computation.See http://www.dotnetperls.com/backgroundworker for more on background worker threads.