multithreading - how to make the silverlight page to wait for few seconds -
i build silverlight application in showing progress bar before content loaded , need pass progress bar few seconds , need close..
i using system.threading.thread.sleep(1000) makes ui freeze.
i need alternative in silverlight in should not freeze ui , process should wait time...
by default on ui thread, time-consuming task block ui. prevent this, push execution background thread -- 1 way task.factory
:
task.factory.startnew( () => { thread.sleep(1000); });
note that, if want ui (which suppose would), you'll need ui thread. (if background thread tries change ui, runtime throw exception.) using dispatcher:
task.factory.startnew( () => { // sleep on background thread thread.sleep(1000); // when complete, return ui thread prevent access violation application.current.dispatcher.begininvoke( () => { // ui stuff here }); });
Comments
Post a Comment