I have a WPF application using PRISM. I have a login screen and on successfuly logging in a new view containing a TileListView with many items appears. This needs over 10 seconds to render because control has to calculate a lot etc. All this uses the UI thread by standard behaviour, because rendering in WPF is done in UI thread. Is it possible to display a WaitControl like a spinner or just a simple animation in seperate window or something like this? Now to animation stops at the time, the control is rendered in UI Thread.
Asked
Active
Viewed 1,599 times
2
-
Would it be possible to refactor so that UI things are bound to DependencyProperties that are assigned after calculations are executed in background threads? Seems like it could be a problem that so much is happening on the UI thread – Matt Thomas Mar 09 '17 at 14:43
-
The control is from Telerik so I could not modify:/ – Michi-2142 Mar 09 '17 at 14:47
-
I see. A spinner in the same window definitely wouldn't work--its spin animation would happen on the same bogged down UI thread, so it wouldn't spin well. But perhaps your idea of creating another window or something to overlay might work. You'd just have to know when the control has finished loading. Could you explain a little more what the control is calculating? That might help us identify another solution – Matt Thomas Mar 09 '17 at 14:50
-
I don't know in detail what happens in the control. The only thing I am passing is the ItemsSource via Binding to ViewModel. This objects only contains information about the tile description but this is not the problem. It could be any control which is slow in rendering.. – Michi-2142 Mar 09 '17 at 14:54
-
Thanks. Does that mean the items being passed in do nothing on the UI thread themselves, but there are so many of them (tens of thousands of them? millions of them?) that the TileListView can't handle them all quickly? – Matt Thomas Mar 09 '17 at 14:58
2 Answers
4
You could create a new window that launches in a separate thread. Please refer to the following blog post for an example of how to do this.
Launching a WPF Window in a Separate Thread: http://reedcopsey.com/2011/11/28/launching-a-wpf-window-in-a-separate-thread-part-1/
Then you just start this thread that displays the window just after you have validated the credentials and just before your heavy rendering is about to begin.
This is probably the best thing you can do and it should also be a pretty easy thing to implement.
Edit - Including code from above link to be recorded for posterity:
using System.Threading;
using System.Windows.Threading;
void LoadWindowInThread()
{
Thread newWindowThread = new Thread(new ThreadStart(() =>
{
// Create our context, and install it:
SynchronizationContext.SetSynchronizationContext(
new DispatcherSynchronizationContext(
Dispatcher.CurrentDispatcher));
// Create and configure the window
Window1 tempWindow = new Window1();
// When the window closes, shut down the dispatcher
tempWindow.Closed += (s, e) =>
Dispatcher.CurrentDispatcher.BeginInvokeShutdown(DispatcherPriority.Background);
tempWindow.Show();
// Start the Dispatcher Processing
Dispatcher.Run();
}));
newWindowThread.SetApartmentState(ApartmentState.STA);
// Make the thread a background thread
newWindowThread.IsBackground = true;
// Start the thread
newWindowThread.Start();
}
0
you can use SplashScreen to display untill the background process is completed. Refer this Splash Screen in WPF

Manikandan Sekar
- 73
- 2
- 16