while(true)
in UI thread is a problem, rather than Thread.Sleep
. And the best solution depends: use timer to run small jobs periodically, create background task/thread to do a job and invoke, do all job in UI thread regularly releasing it by using await Task.Delay
, fire-and-forget first task and use continuation to run second, etc.