0

I'm trying to show a loader animation when my application it's blocked for more than 500ms. I want that to be automatic, I don't want to add any piece of code before every long operation.

I know that in WinForms it was possible (I used this: https://snipplr.com/view/24851/), but It does not work in WPF. I've found that I can do that with the mouse cursor(display Hourglass when application is busy)

I've tried to launch a window with a spinner. I've found this answer (https://stackoverflow.com/a/21411656/10820863), that works detecting long operation. Problem is that if I launch a window from a thread that is not the main one, I got a ThreadException because it's not the main thread. If I use Application.Current.Dispatcher.BeginInvoke method, the window appears only when UI is not blocked anymore.

So, how can I automatically detect long operation and show a loading window/page/image/whatever if it lasts for more than 500ms?

[EDIT] I don't want to add code to every long function, evaluating case for case which function can be long. I'd prefer to have an automatic method that do that for me.

Emanuele
  • 723
  • 4
  • 15
  • 2
    The problem lies more in the way you wrote your application: executing long-running code in the UI thread. So the fix is obvious but not simple: rewrite parts of your application to execute long-running code using tasks or a background thread. – aybe Oct 25 '19 at 13:25
  • Unfortunately this is very complex. There are a lot of long operations with UI interaction (and I think there will be lot of problem with threads). – Emanuele Oct 25 '19 at 13:43

0 Answers0