How to display a WPF page or window without waiting for heavy processes to finish

霸气de小男生 提交于 2019-12-12 23:20:23

问题


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

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!