I have a long-running operation that have to be done in UI thread (involves UI elements that cannot be freezed). I want to display a busy indicator before running the operation.
busyIndicator.Visibility = Visibility.Visible;
LongRunningMethod();
busyIndicator.Visibility = Visibility.Collapsed;
Of course this does not work because rendering does not occur until the operation finishes. I tried to use Task.Yield() to run the rest of method asynchronously:
busyIndicator.Visibility = Visibility.Visible;
await Task.Yield();
LongRunningMethod();
This also does not work, as far as I understand, because the rest of the method is prioritized higher than rendering operation.
How can I do it using TPL?
UPD: LongRunningMethod
cannot be run in a separate thread by its nature (works with complex WPF 3D models), and anyway I cannot afford to make changes in it now. So please don't offer solutions based on running it completely or partially on a separate thread.