Updating a form through another form in C# -
i have button in form. when button clicked, button click function called. in function @ first form (let's call object form2 class form2) created objects including labels , progress bars (these objects created through form2 constructor). form2.show() called. while loop comes end of variables updated. use these variables update several objects in form2. problem form objects not shown rightly until button click function finished. example instead of labels, white rectangles shown. tried using thread.sleep(1000) after while see if objects shown rightly didn't have effect on form2 shape. used messagebox.show() after while , worked surprisingly! objects shown correctly in form2. appreciate if problem , how can solve it.
you're blocking ui thread, preventing updates until release ui thread continue handling other messages sent it.
if have long running cpu bound work, should offloading background thread. if have io or other non-cpu bound work should doing asynchronously, rather synchronously blocking on it, ui thread can continue processing other events.
Comments
Post a Comment