I am working on a Silverlight for Windows Embedded project and running into a problem with my UI thread. Currently the application UI thread must continually update its display based on data stored in a shared memory file and then sleep for a specified number of milliseconds before updating the UI once again. So in essence the code is something like the following:
while(true){
UpdateUI(); //gets data from shared memory and updates graphics
Sleep(250);
}
However, as I am sure some of you know, it is not recommended to use Sleep() within the main Silverlight UI thread. Sure enough, my entire embedded system will crash after running for 20-30mins and I have identified the call to Sleep() as the issue.
What I need is an alternative method to update the UI, pause for some amount of time, and then update the UI again, repeating this process ad infinitum.
As far as I am aware, the embedded nature of the project does not allow me to use some of the obvious alternatives to Sleep() that would be a better solution in the UI thread (i.e. Join()).
Any suggestions would be greatly appreciated!
A timer is a far better route then a loop, especially a loop with a Sleep in the UI thread. A simple call to SetTimer or timeSetEvent is probably what you’re after.