问题
I am working on a WPF Browser Application. The problem is that I have to load some heavy services in the beginig, this causes to see a white page for some seconds before the page components get loaded. Is there a way to avoid this somehow by loading the page without waiting for the heavy processes to finish?
Here is the thing I am trying now, and it didn't work:
public Page1()
{
InitializeComponent();
}
private void Page_Loaded_1(object sender, RoutedEventArgs e)
{
// Initialize and configure kinect
// This takes some seconds
}
I was thinking the page_loaded event happens after all the components of the page have finished loading. But still it waits for the processes to finish and I get some seconds of a white page in the begining...
回答1:
You can use BackgroundWorkers to handle the long-running operations. This will keep the UI responsive while the task(s) are running. Go here to learn more: http://msdn.microsoft.com/en-us/library/system.componentmodel.backgroundworker.aspx
回答2:
Could use BackGroundWorker and could call it in either event.
You cannot build or load a UI control in the background.
Build the data and (non UI) objects in the background and then bind on callback.
BackgroundWorker Class
来源:https://stackoverflow.com/questions/12690699/how-to-display-a-wpf-page-or-window-without-waiting-for-heavy-processes-to-finis