c# - Windows forms - wait until form is completely drawn (painted) -


i designed wich objective run method. it's please wait form.

i give delegate it, , call showdialog. takes delegate , executes in shown event. after that, hide().

the purpose solely there telling user wait until delegate run.

but: starts executing delegate before it's show. mean, form appears in screen, please wait label gets stuck running code, being shown late, or not shown. (an empty rectangle remains in middle of form).

i make form wait maybe 2 seconds before running delegate, there way (better , assured) call delegate after form painted, label shown???

thanks.

try using backgroundworker backgroundworker component has 4 events.

you need implement 2 of them: dowork , runworkercompleted

the dowork method executes in thread, , work ( or in case, call delegate) runworkercompleted called when work finished, , can call hide() method there.

if happen want show progress, can implement progresschanged event, allows pass in percentage completed , object ( pass message on i'm doing )

then drawing normal, , call background worker runworkerasync called.

public class wait : form {     backgroundworker _bgworker = new backgroundworker();      public delegate void toexecutedele(object args);       public toexecutedele toexecute;       public wait()     {         initializecomponent();          _bgworker.dowork += new doworkeventhandler( dowork )         _bgworker.runworkercompleted += new runworkercompletedeventhandler (workdone);      }        public void execute(object args)     {          // display stuff (label, start progress bar pulsing, maybe enable disable stuff              dispalystuff(" plate wait");           _bgworker.runbackgroundasync(args);      }      private void dowork(object sender, doworkeventargs e)     {           if( toexecute != null )             toexecute(e.argument);       }        public void workdone(object sender, runworkercompletedeventargs e)     {           // display error if there exception in event args          hide();      } } 

everything in dowork happens in thread, else runs in ui thread, , wont hang while executing.


Comments

Popular posts from this blog

linux - xterm copying to CLIPBOARD using copy-selection causes automatic updating of CLIPBOARD upon mouse selection -

c++ - qgraphicsview horizontal scrolling always has a vertical delta -