views:

230

answers:

5

I use C# to write windows applications with the .NET framework. How can I decrease startup time for these applications? My applications feel very slow during startup and initialization, particularly when showing the initial form.

My application works with an Access (MDB) database to save data. In some forms it loads data, but the first time the application shows any given form, it takes a long time to display.

I've tried using NGen to decrease the startup time, but it did not help me as expected.

+7  A: 

Make sure your application does as little work as possible on startup.

You can change your startup code to defer startup tasks to a secondary thread.

I'd give a more detailed answer, but your question is very broad and not detailed enough.

Oded
+3  A: 

First you need to diagnose what functions are running during this startup period, and analyze how much of the startup delay each of the functions is consuming...

Then once you know that, if one or two of them are consuming the bulk of the time, and do not involve the initially displayed UI screens, execute those functions on a separate thread.

Charles Bretana
+1  A: 

You might want to use EQATEC Profiler to profile your application and see which function calls take a long time. It makes it a bit easier to visualize what is happening in the background and where improvements could be made.

tomlog
+2  A: 

Look into lazy loading. This involve loading data and populating a class when the data is first requested, rather than when the class is instantiated.

// member variable
        private DataSet _employeeDataSet = null;

    // property
    public DataSet EmployeeDataSet
    {
        get
        {
            if (_employeeDataSet == null)
                _employeeDataSet = GetEmployeeDataSet();

            return _employeeDataSet;
        }
    }
runrunraygun
A: 

I'm on a team building a .NET application in C#, and we run into this all the time. There is a profiler, but nobody bothers to use it because 1) it's a bit of a bother, and 2) the output is confusing. What I do is start it under the IDE, and while it is being piggishly slow, I just pause it and ask it what it is doing and why, by examining the call stack.

Since it is being slower than it's going to be, it is because it is doing some things that will be removed or done differently. These things generally consist of function calls requesting things like: internationalizing strings that don't need to be internationalized, loading things multiple times, initializing data structures that are there just for completeness and are going to be replaced later, unzipping and zipping things more than necessary. All of these take the form of mid-stack function/method calls and when they show up on multiple stack samples are simply crying out to be attended to.

It is good to try to foresee these problems and not put them in, but you can count on such problems creeping in, despite best intentions. The method of stack sampling (stackshots) is effective at finding them.

Mike Dunlavey