I am working on a WPF Browser Application. I want to know how I can understand when the loading of a page is finished and the components are shown to start loading the heavy background services. Otherwise I just see a white page for some seconds untill all the services are loaded… Any recommendations to solve this problem?
Here is the thing I have tried:
public Page1()
{
InitializeComponent();
}
private void Page_Loaded_1(object sender, RoutedEventArgs e)
{
// Just some heavy process in the begining
int j = 1;
for (int i = 0; i < 10000000; i++)
{
for (int k = 0; k < 1000; k++)
j=j * 2;
}
MessageBox.Show("ready");
}
However, the page components don’t get loaded in the page untill the processes in page_loaded is finished. Without having the heavy process in the page_loaded, every thing loads very quickly, so there is not any problem in UI.
UPDATE: The thing I understood from loaded event for page or window is that it gets triggered when the page or window gets loaded, and loading of the components and the controlls on the page even the style of it will occure after that… and I don’t seem to find any event that shows the loading of the controlls is completed…
UPDATE2: A better solution for my problem is to use BackgroundWorker or the Dispatcher to run the heavy process on background. As discussed in this post.
You need to implement threading in your application for this. if you write any code in page load method. Your page will not rendered until the load method is completely executed. so you can use Background Worker and run the processes in background