I know I'm missing something stupid, the "StartProcess" Method is making the UI unresponsive and no amount of googling and tutorials has led me to an answer.
Here is my code:
public MainWindow()
{
InitializeComponent();
txtBlock.Text = "Testing";
Initialize();
}
public void Initialize()
{
uiScheduler = TaskScheduler.FromCurrentSynchronizationContext();
StartProcess();
}
async void StartProcess()
{
Task<int> result = Task.Factory.StartNew(() =>
{
txtBlock.Text += ("\n starting updater");
while (true)
{
Thread.Sleep(3000);
}
return 0;
}, CancellationToken.None, TaskCreationOptions.LongRunning, uiScheduler);
}
Some background: I'm building an app that has to poll the DB every 5mins and update the UI with a to-do list for the user, hence the while(true) loop. The app has to poll the DB continuously throughout its lifetime.
Task.Delayinstead ofThread.Sleep. At the moment you seem to be callingThread.Sleepon the UI thread which will make your UI unresponsive. Also, simply making your methodasyncdoesn't perform magic.