Controls doesn't show if heavy process

I use c# in winform.

Before a very heavy function, I want to show a waiting form to prevent the user. The form opens, but the controls in it are not drawn.

In the following code, waitingForm is a little form, with only a textbox and a progressbar

using (WaitingForm waitingForm = new WaintingForm()) { waitingForm.Show(); HeavyFunction(); }

I see only two white rectangles, where the controls should appear. Why this happens ?

-------------Problems Reply------------

You can't show the waiting form before the heavy processing and expect the UI to remain responsive. The thread that you're clogging up with HeavyFunction() is the same one that is responsible for drawing forms, controls and maintaining the UI. Use a BackgroundWorker or the ThreadPool to offload the heavy processing to another thread.

EDIT: Also, please consider Ron Beyer's input regarding async/await

Category:c# Views:1 Time:2018-11-06

Related post

Copyright (C) dskims.com, All Rights Reserved.

processed in 0.249 (s). 11 q(s)