Unable to close new WPF window until all UI threads are returned even if dispatcher priority is set to background

Humble Rumble

I am new to WPF and making it up as I go along so apologies if I have done anything drastically wrong.

I have a main window that makes a new 'error window' once particular user controls have completed their business. This new error window returns a 'loading placeholder' to UI whilst a background thread is updating another part of the 'error window'.

        ErrorsWindow errorWindow = new ErrorsWindow();
        errorWindow.LoadingPlaceholder.Text = string.Format(@"Loading...
                                      Please wait {1} minutes and {0} seconds to see potential errors",
                                      ConfigurationManager.AppSettings["ErrorWindowWaitSeconds"],
                                      ConfigurationManager.AppSettings["ErrorWindowWaitMinutes"]);
        errorWindow.Show();
        this.Dispatcher.BeginInvoke((Action)(() =>
        {
            errorWindow.SetupWindow();
        }), System.Windows.Threading.DispatcherPriority.Background);

So my errorWindow shows up in the UI with the loading placeholder text set correctly. The UI then waits 1 minute 30 seconds for the errorWindow.SetupWindow() method to complete. The issue is that during this wait period I cannot close the window until the errorWindow.SetupWindow() method has completed. Is there a way to allow the window to close and just abort the background thread?

EDIT: I cannot use a backgroundworker or a task as I need to update the UI elements inside the errorWindow.SetupWindow() method

Thankyou in anticipation

Humble Rumble

I found the answer to my question on another stackoverflow post here:

How to make some Tasks change my WPF controls

It involves doing the long running task on another thread(using System.Task) then using the dispatcher on the separate thread to affect the UI thread with any UI related changes.

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

How to block new threads until all threads are created and started

From Dev

How do I create a new Window in electron js such that the original window is unusable until i close the new window?

From Dev

Unable to close new window after using mailto in javascript

From Dev

Catch-all Exception Handler for non-UI Threads in WPF

From Dev

WPF UI on multiple threads?

From Dev

WPF UI on multiple threads?

From Dev

Unable to close current window

From Dev

WPF Dispatcher on non-UI thread

From Dev

Waiting for Dispatcher.Invoke in WPF UI thread

From Dev

WPF what happened to the dispatcher object on UI elements?

From Dev

WPF Dispatcher on non-UI thread

From Dev

WPF what happened to the dispatcher object on UI elements?

From Dev

How to set up UI culture for all the threads in framework 4.0?

From Dev

How to set up UI culture for all the threads in framework 4.0?

From Dev

How to set a on click effect on a textBlock and open a new WPF window?

From Dev

How to set a on click effect on a textBlock and open a new WPF window?

From Dev

How do I set the default size of a new window in WPF?

From Dev

Close WPF window after animation

From Dev

Set the Background of all Rectangles in a WPF App C#

From Dev

How to set the background image of all windows in wpf application

From Dev

Is it possible to set the priority of the threads in Stream.parallel()?

From Dev

Set focus to background window

From Dev

WPF set parent (Window)

From Dev

GIMP: Set All New Images to Default Transparent Background?

From Dev

Background worker component for a WPF window

From Dev

WPF popup wont close even with StaysOpen="false"

From Dev

Set different background color for all cells in a JTable Column, based on the String returned by the database Query

From Dev

UI Freezing Even After Using Threads

From Dev

UI Freezing Even After Using Threads

Related Related

  1. 1

    How to block new threads until all threads are created and started

  2. 2

    How do I create a new Window in electron js such that the original window is unusable until i close the new window?

  3. 3

    Unable to close new window after using mailto in javascript

  4. 4

    Catch-all Exception Handler for non-UI Threads in WPF

  5. 5

    WPF UI on multiple threads?

  6. 6

    WPF UI on multiple threads?

  7. 7

    Unable to close current window

  8. 8

    WPF Dispatcher on non-UI thread

  9. 9

    Waiting for Dispatcher.Invoke in WPF UI thread

  10. 10

    WPF what happened to the dispatcher object on UI elements?

  11. 11

    WPF Dispatcher on non-UI thread

  12. 12

    WPF what happened to the dispatcher object on UI elements?

  13. 13

    How to set up UI culture for all the threads in framework 4.0?

  14. 14

    How to set up UI culture for all the threads in framework 4.0?

  15. 15

    How to set a on click effect on a textBlock and open a new WPF window?

  16. 16

    How to set a on click effect on a textBlock and open a new WPF window?

  17. 17

    How do I set the default size of a new window in WPF?

  18. 18

    Close WPF window after animation

  19. 19

    Set the Background of all Rectangles in a WPF App C#

  20. 20

    How to set the background image of all windows in wpf application

  21. 21

    Is it possible to set the priority of the threads in Stream.parallel()?

  22. 22

    Set focus to background window

  23. 23

    WPF set parent (Window)

  24. 24

    GIMP: Set All New Images to Default Transparent Background?

  25. 25

    Background worker component for a WPF window

  26. 26

    WPF popup wont close even with StaysOpen="false"

  27. 27

    Set different background color for all cells in a JTable Column, based on the String returned by the database Query

  28. 28

    UI Freezing Even After Using Threads

  29. 29

    UI Freezing Even After Using Threads

HotTag

Archive