Label text doesn't get updated until the whole loop is completed

自作多情 提交于 2019-12-06 02:10:27

To answer your question about why you have to do it: Windows Forms Programs run everything in a single thread - the UI thread. This means it must execute code in order, so that it will finish a function before it can switch back to the UI code. In other words, it can't update the pictures until after its finished with the function, so if you updated the picture 100 times, only the last one will actually get updated. Using the Invalidate/Update code tells the compiler to "pause" execution of the function and forces it to update the UI instead of waiting till the end of the function. Hope that helps!

// Code fragement...
// 5 cent solution, add Invalidate/Update
label1.Text = iterations.ToString();
label1.Invalidate();
label1.Update();
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!