How can I create WPF controls in a background thread?

后端 未结 8 611
终归单人心
终归单人心 2021-01-17 15:49

I have method which create background thread to make some action. In this background thread I create object. But this object while creating in runtime give me an exception :

8条回答
  •  天涯浪人
    2021-01-17 16:15

    HTH:

        void Background_Method(object sender, DoWorkEventArgs e)
        {
            // Time Consuming operations without using UI elements
            // Result of timeconsuming operations
            var result = new object();
            App.Current.Dispatcher.Invoke(new Action((res) =>
                {
                    // Working with UI
                    TreeView tv = new TreeView();
                }), result);
        }
    
        

    提交回复
    热议问题