c# - Making a text appear under a button for half a second -
i want make button perform action , let user know done. tried making label ander button, pause, making disappear.
private void button1_click(object sender, eventargs e) { // action label1.text = "done!"; system.threading.thread.sleep(500); label1.text = ""; }
but doesn't work. mistake?
as grant says in answer, you're blocking ui thread. simplest solution spawn new task
update you, releasing ui thread.
the task
can use invoke
push update ui thread after sleep
.
in case, translates this:
private void button1_click(object sender, eventargs e) { // action label1.text = "done!"; new taskfactory().startnew(() => { thread.sleep(5000); invoke((action)(() => label1.text = string.empty)); }); }
Comments
Post a Comment