Closing windows is slow?

Docking/MDI for WPF Forum

Posted 13 years ago by SledgeHammer01
Version: 10.2.0532
Avatar
We are using 10.2 b 532 on Windows 7. Pretty beefy machines. We have noticed that it is slow to close docking windows. We use the ribbon and ribbon theme on the docking windows:

Our main window layout is:

(2 tabbed windows in a toolwindow) | Main Document View

What we did was implement "Close All But This" and "Close All" commands in a DockSiteEx : DockSite class.

They look like:

        private void dockWndCloseAllButThis_Executed(object sender, ExecutedRoutedEventArgs e)
        {
            List<DocumentWindow> docWindows = new List<DocumentWindow>();
            DockingWindow dw = (DockingWindow)e.Parameter;

            foreach (DocumentWindow wnd in DocumentWindows)
            {
                if (wnd == dw)
                    continue;

                docWindows.Add(wnd);
            }

            foreach (DocumentWindow wnd in docWindows)
                wnd.Close();

            e.Handled = true;
        }

        private void dockWndCloseAllButThis_Executed(object sender, ExecutedRoutedEventArgs e)
        {
            List<DocumentWindow> docWindows = new List<DocumentWindow>();

            foreach (DocumentWindow wnd in DocumentWindows)
                docWindows.Add(wnd);

            foreach (DocumentWindow wnd in docWindows)
                wnd.Close();

            e.Handled = true;
        }
So nothing much too it. If we have 10 windows or so, it takes a few seconds (2 - 4) to close all the windows. Is there any way to speed this up?

Could be something on our end I suppose, but wanted to check if there is some obvious issue with the code.

EDIT: Oh yeah, we get a LOT of System.Windows.Data Error: 4 when we close the windows. I know you have said we can ignore these, but it REALLY effects closing windows speed. 4 seconds to close 10 windows is a bit much.

EDIT 2: We also have a different window type that doesn't cause the System.Windows.Data errors and its a bit faster, but not by a whole lot.

EDIT 3: closing 3 of the windows that cause the errors (because they have property grids in them) spits out 412 warnings :)


[Modified at 03/01/2011 05:19 PM]

Comments (3)

Posted 13 years ago by Actipro Software Support - Cleveland, OH, USA
Avatar
Hello,

You should probably close the "selected" windows last, in a second loop. If you have say 10 windows with the first selected and close them in order, then a new document must be "selected". In terms of the tabbed MDI, this means that the UI must be updated.

For example, this method takes about 7 seconds to close 100 very simple windows in our Features demo:
private void OnCloseAllDocumentsMenuItemClick(object sender, RoutedEventArgs e) {
    for (int i = dockSite.Documents.Count - 1; i >= 0; i--)
        dockSite.Documents[i].Close();
}
If we rework it like the following, the time drops down to about 2 seconds:
private void OnCloseAllDocumentsMenuItemClick(object sender, RoutedEventArgs e) {
    for (int i = dockSite.Documents.Count - 1; i >= 0; i--) {
        if (!dockSite.Documents[i].IsSelected)
            dockSite.Documents[i].Close();
    }
    for (int i = dockSite.Documents.Count - 1; i >= 0; i--)
        dockSite.Documents[i].Close();
}
This should also reduce the need to update any bindings in the "non-selected" windows, for them only to be immediately detached.


Actipro Software Support

Posted 13 years ago by SledgeHammer01
Avatar
Hi,

I made the changes as you suggested, but I didn't see any difference. My close all function is now like this:

            DateTime t1 = DateTime.Now;

            List<DocumentWindow> docWindows = new List<DocumentWindow>();

            foreach (DocumentWindow wnd in DocumentWindows)
                docWindows.Add(wnd);

            foreach (DocumentWindow wnd in docWindows)
                wnd.Close();

            //for (int i = Documents.Count - 1; i >= 0; i--)
            //{
            //    if (!Documents[i].IsSelected)
            //        Documents[i].Close();
            //}
            //for (int i = Documents.Count - 1; i >= 0; i--)
            //    Documents[i].Close();

            DateTime t2 = DateTime.Now;
            TimeSpan ts = t2 - t1;

            System.Diagnostics.Debug.WriteLine(ts.TotalMilliseconds);

            e.Handled = true;
So with that original version, it takes 2577ms to close 10 of the error 4 producing windows... when I comment out the top block and go to your code, it only goes down to 2404ms. Also keep in mind that the WriteLine() call is BEFORE the debugger dumps out all the error 4s, so that time is not included.

Your idea originally made sense, but it seems to me that (at least in my case) the code is in a direct menu item clicked handler and executes in a tight loop, so no UI updating is done... could be wrong though.

As comparion, my other doc type which doesn't produce the error 4s, it took about 900ms to close 10 with either code.

Running without the debugger attached made no difference either.
Posted 13 years ago by Actipro Software Support - Cleveland, OH, USA
Avatar
Hello,

Unfortunately, we'd need a sample to profile/debug. If you can please put together a small sample project the reproduces the slow closing and email it over, then we can take a closer look.

Closing non-selected items should help either way. You can verify this with our sample application by adding a close all menu item, and adding a lot of windows. But again, those are very simple windows and your case probably has more complex UIs.


Actipro Software Support

The latest build of this product (v24.1.1) was released 2 months ago, which was after the last post in this thread.

Add Comment

Please log in to a validated account to post comments.