im developing a medium sized WPF application, i already got the first screen mostly working, but i am wondering about UI locking.
Right now, when opening a tab my UI doesnt lock since i use code like this for loading data from the DB at the start.
await Task.Run(() => dbService.loadData());
However i noticed that its sometimes locking when i calculate something that takes even a slight amount of time. Or if i run an update command to my database.
Do i just need to wrap pretty much everything in this strange async Task construct? That can't be right.
This gets especially annoying since i put a IsLoading boolean around it, which is bound to an indicator and disables the UI. Disable/enable the UI for a whole .3 seconds makes for a really user unfriendly flickering effect. So i came up with this construct around my update command.
var t = new Timer(500);
t.Elapsed += (s,e) () => IsLoading = true;
t.Start();
await Task.Run(() => dbService.UpdateData());
t.Stop();
IsLoading = false;
I feel like i didnt describe my problem very well, but this code is it.
There have to be smarter/shorter ways to solve UI locking. I cant be forced to do all of this every time just to call one line. Even with extracting it into a helper method it seems silly.