views:

77

answers:

1

At the moment we have a problem with the startup of a middle-sized WPF-application. It takes about 15 seconds to load completly. We wondered what it takes that long.

In the event Application_Startup of App.xaml a controller gets initialised. This controller lives in a separate 'business' assembly, which calls in turn to the 'data' assembly to gather information about the user and so on. This assemblies are relative small, 160k and 60k.

The time it takes to enter this event was 15 seconds. So we separated the code in another method and call it in the event. With this change, we found the debugger enter the Application_Startup event directly after startup. However, from the point it reaches the line which calls the separated method and enters this methods it took again 15 seconds.

In this period of time nothing happend in the output or callstack window of Visual Studio. So questions are:

  1. Is there any way to see what is happening after a method call and before entering the method?
  2. Are assemblies needed in a method loading in this period of 15 seconds? If true, what are ways to shorten this time?

Thanks in advance for replies.

edit, the requested code of the separated method:

        try
        {
            // Check whether debug mode is enabled or not.
            string[] commandArgs = Environment.GetCommandLineArgs();
            ApplicationLog.DebugMode =
                (commandArgs.Length > 1 &&
                (commandArgs[1].IndexOf("debug") > 0) ||
                (commandArgs.Length > 2 && commandArgs[2].IndexOf("debug") > 0));

            // Logging startup.
            ApplicationLog.Log("Starting at " + Environment.MachineName, 21003);

            // Check to start configtool or main application.
            if (commandArgs.Length > 1 &&
                (commandArgs[1].IndexOf("config") > 0 || commandArgs[2].IndexOf("config") > 0))
            {
                ConnectionStringWindow window = new ConnectionStringWindow();
                window.DataContext = new ViewModels.ConnectionStringViewModel();
                window.Show();
            }
            else
            {
                // The main window.
                MainWindow mainWindow = new MainWindow();
                mainWindow.Closing += mainWindow_Closing;

                // New ViewModel.
                mainWindow.DataContext = new ViewModels.MainWindowViewModel(mainWindow);

                // Display.
                mainWindow.Show();
            }
        }
        catch (Exception ex)
        {
            ApplicationLog.Log(ex, 22001);

            if (ApplicationLog.DebugMode)
            {
                Microsoft.SqlServer.MessageBox.ExceptionMessageBox box = new Microsoft.SqlServer.MessageBox.ExceptionMessageBox(
                    ex.Message,
                    "Application",
                    Microsoft.SqlServer.MessageBox.ExceptionMessageBoxButtons.OK,
                    Microsoft.SqlServer.MessageBox.ExceptionMessageBoxSymbol.Error);
                box.InnerException = ex;
                box.ShowCheckBox = false;

                box.Show(null);
            }
            else
            {
                MessageBox.Show(ex.Message, "Application", MessageBoxButton.OK, MessageBoxImage.Error);
            }

            // Close application.
            Application.Current.Shutdown();
        }
+1  A: 

You can use Process Monitor tool to see what is going on behind the scenes. At least you might see which files (e.g. .NET assemblies) are read, which directories are scanned and so on. You can also uncheck 'Just my code' checkbox in the VS debugger options and check 'Enable .NET Framework source stepping option' in the same place. This will produce more detailed stack trace at least. If nothing helps you can use WinDbg to step through both managed and unmanaged code.

Igor Korkhov
Seems it takes so long to optimize the application (process profiling). Thanks.
Monty