CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 11 of 11
  1. #1
    Join Date
    Mar 2013
    Posts
    4

    C# Load times and .NET resources

    As most of you probably know, a cold start of a .NET program takes a little bit to load. After that the warm starts come right up because all the .NET business is cached. My question is, is there anyway to have a splash screen come up as the .NET resources load so the user doesn't think the programs unresponsive and tries to keep opening it? I tried a normal splash that does all the loading before the main form comes up, but that only comes up after the fact, so its of little help. I looked into maybe using WPF but I couldn't find any solid info on how to implement this.
    Any help would be great, thanks guys!

    (Using VS 2008 and .NET 4.0 but upgrading to 4.5, so answer referring to either works)

  2. #2
    Arjay's Avatar
    Arjay is offline Moderator / EX MS MVP Power Poster
    Join Date
    Aug 2004
    Posts
    13,490

    Re: C# Load times and .NET resources

    What are you doing that is causing the delay starting up?

    Once you identify those items, can you defer loading them during startup (for example, can you load these expensive items in a separate thread)?

  3. #3

    Re: C# Load times and .NET resources

    In the main(), can you show the splashscreen first and then load components ? Or load the ones absolutely necessary to show the splashscreen itself in a background thread and then load the rest?

    --
    http://savensearch.blogspot.com/

  4. #4
    Join Date
    Mar 2013
    Posts
    4

    Re: C# Load times and .NET resources

    I'm trying to do something just like that, I'm trying to find a way to load just enough to get a splash screen up then load the rest while the the splash screen is up I just can't seem figure out how to do this.

  5. #5

    Re: C# Load times and .NET resources

    Are you doing it in a different thread? Try Thread.Sleep(30) and then a refresh in a thread while the main() loads?

  6. #6
    Join Date
    Mar 2013
    Posts
    4

    Re: C# Load times and .NET resources

    I've tried putting it in main and showing it before anything else even loads then building the mainForm with the splash screen up. The delay is still there because I think (and I could be wrong) that its still loading the .NET components first in order to show that first splash screen. I can't seem to find a way to have it pop up right away.

  7. #7
    Arjay's Avatar
    Arjay is offline Moderator / EX MS MVP Power Poster
    Join Date
    Aug 2004
    Posts
    13,490

    Re: C# Load times and .NET resources

    Build a test project that only shows a splash screen and compare that with you load times. If that loads fast enough, then start disabling stuff from your app until you find the items that are slowing the app down. Move the loading of those items into another thread. P.S. Sleep(...) isn't going to help.

  8. #8
    Join Date
    Mar 2013
    Posts
    4

    Re: C# Load times and .NET resources

    Sounds good, I'll try that when I get off work. Is there a way to see a log of load times for each item loaded?

  9. #9

    Re: C# Load times and .NET resources

    I did it in a Medical Imaging project - it was slow loading - once loaded it was fast - that was bcos we had to load all the images (scans) in memory for fast processing. But it wasn't at the startup, so people knew its coming up when the cursos shows hourglass and didnt click on it multiple times.

  10. #10

    Re: C# Load times and .NET resources

    Arjay is right - sleep() wont help as the program is starting up...tried it.

  11. #11
    Arjay's Avatar
    Arjay is offline Moderator / EX MS MVP Power Poster
    Join Date
    Aug 2004
    Posts
    13,490

    Re: C# Load times and .NET resources

    Maybe a good way to think of your program and loading is to think of a tree with a trunk and branches and to think that it takes time to compile and load the trunk and any branches.

    Think of the trunk as the shell of your program. Branches are references that you 'new' up during startup which also need to be compiled and loaded.

    For fastest loading what you want to try to accomplish is a tree with only a trunk (or a trunk with a couple of very small branches).

    To this end, minimize the number of 'branches' by only 'new'ing up the branches that are absolutely necessary to get your program running.

    For the non-essential startup branches, only new these up on-demand like when a user initiates some action, or load these in a separate thread and use a delegate to signal the user that everything has been loaded (this can be as simple as a status messages stating "loading..." and enabling menu items or buttons when completed).

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured