locked
4 to 4.5 second delay before window visually activated after initialization. RRS feed

  • Question

  • As of recently (two weeks) I noticed that a WPF applications take more time to appear on screen, even though the window has already initialized and loaded (events have fired). After the Loaded event has been raised it takes 4 to 4.5 seconds before the Activated event has been raised and the window is visible on screen.

    This issue is reproducable with a new WPF application project. The windows event logs also show no warnings or errors regarding this. I have also ran 'ngen update'-command but nothing seems to change.

    I don't know what other steps I can to undertake to find and fix this issue, but it interrupts fast development iterations. Any advice regarding this would be appreciated.

    Monday, January 12, 2015 8:29 PM

Answers

  • Winforms always loads much faster than wpf.

    The button thing is probably just measure arrange.

    By refreshing visual studio I mean install. Refresh is one of the re install options.

    The fact it affects even new projects means it's not a corrupt csproj.

    Old ssd used to have a fairly short lifetime. Performance degraded.

    I suppose that's also a possible cause.


    Please don't forget to upvote posts which you like and mark those which answer your question.
    My latest Technet article - Dynamic XAML

    • Marked as answer by Barry Wang Tuesday, January 27, 2015 9:50 AM
    Sunday, January 18, 2015 7:40 PM

All replies

  • Hello,

    Do you mean any WPF project run on your machine can reproduce this issue?

    You may check the following article: Improving WPF applications startup time

    http://blogs.msdn.com/b/jgoldb/archive/2007/10/10/improving-wpf-applications-startup-time.aspx

    Where the author introuduced some ways which may helpful to you.

    Best regards,



    Barry
    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.

    Tuesday, January 13, 2015 9:08 AM
  • My understanding:

    2 weeks ago if you created a new solution with just an empty mainwindow in it, that would load quickly.

    Now you create a new solution with just an empty mainwindow in, that loads noticeably slower.

    Paths to the code are similar - same drive, same length of path.

    Correct?

    I mention the drive and path because long paths can cause problems.

    A path with an unusual character in it can cause problems ( my name has an apostrophe ' in it and that causes a problem if I use a personal folder ).

    Type of drive and where it is can make a huge difference.

    Ideally you want a fast SSD on your computer.

    .

    Assuming all that is OK.

    I've seen this sort of behavior due to toolbox problems.

    You can easy try and fix that, see if it makes any difference.

    Right click your toolbox.

    Choose reset toolbox.

    It'll take a while.

    Try your almost empty solution.

    If that's no good then I would refresh visual studio.


    Please don't forget to upvote posts which you like and mark those which answer your question.
    My latest Technet article - Dynamic XAML

    Tuesday, January 13, 2015 9:41 AM
  • Hello Barry, thanks for the fast reply.

    The issue is indeed with every WPF project, but also with WPF applications that I didn't build on this PC.

    I have walked through all the steps to improve that startup time that I could apply, but none fixed the issue.

    Sunday, January 18, 2015 5:52 PM
  • Hello Andy,

    Your understanding is correct. I always work from my SSD's, but I don't think this is causing the issue. My hardware configuration hasn't changed in a year.

    I tried to reset the toolbox, but it didn't fix the issue.

    What do you mean by refreshing Visual Studio?

    Sunday, January 18, 2015 5:55 PM
  • I have done some additional testing. I created a WinForm application to see if the problem also occurs there, but this application starts up immediately and the UI is responsive right from the start.

    I applied some time logging to the empty application:

    using System;
    using System.Diagnostics;
    using System.Windows;
    
    namespace WpfApplication1
    {
      public partial class MainWindow : Window
      {
        public MainWindow()
        {
          Debug.WriteLine("{0:HH':'mm':'ss.fff} Initializing", App.Time);
          
          InitializeComponent();
        }
    
        private void MainWindow_OnActivated(object sender, EventArgs e)
        {
          Debug.WriteLine("{0:HH':'mm':'ss.fff} Activated", App.Time);
        }
    
        private void MainWindow_OnInitialized(object sender, EventArgs e)
        {
          Debug.WriteLine("{0:HH':'mm':'ss.fff} Initialized", App.Time);
        }
    
        private void Window_Loaded(object sender, RoutedEventArgs e)
        {
          Debug.WriteLine("{0:HH':'mm':'ss.fff} Loaded", App.Time);
        }
      }
    }

    The result is:

    19:06:57.428 Initializing
    19:06:57.447 Initialized
    19:07:01.746 Activated
    19:07:01.767 Loaded

    However, when I change Width and Height property from a number to "Auto" in the MainWindows.xaml, the window will appear right away, but the content (a button in my case) will appear after the 4-4.5 seconds delay.

    The close button seems to be responsive during the delay, but closing won't happen after the content is visible.

    Sunday, January 18, 2015 6:18 PM
  • Winforms always loads much faster than wpf.

    The button thing is probably just measure arrange.

    By refreshing visual studio I mean install. Refresh is one of the re install options.

    The fact it affects even new projects means it's not a corrupt csproj.

    Old ssd used to have a fairly short lifetime. Performance degraded.

    I suppose that's also a possible cause.


    Please don't forget to upvote posts which you like and mark those which answer your question.
    My latest Technet article - Dynamic XAML

    • Marked as answer by Barry Wang Tuesday, January 27, 2015 9:50 AM
    Sunday, January 18, 2015 7:40 PM