0

I am loading something that takes a long time in OnPaint function the first time I run my program, and I need a way to show my progress. I already have the progress stuff up, but I just don't know the simplest way to show it.

Want either

  1. Something to keep the form responsive when stucked in OnPaint function for a prolonged period, I am changing the title name to show progression and I want the form to stay responsive!

  2. Pop up something else that is easily created to show progress

btw, I am loading it only OnPaint because I wanted the form to show up so that the user will know that the program opened correctly. Otherwise nothing will happen while the form loads, and the user might think that the program was not even opened.

LarsTech
  • 80,625
  • 14
  • 153
  • 225
  • [DoEvents](http://www.codinghorror.com/blog/2004/12/is-doevents-evil.html) – Jeremy Thompson Jul 18 '12 at 03:36
  • 1
    You shouldn't be processing anything in the paint event. Just draw something quick. We probably need to know *what* you are processing in the paint event. – LarsTech Jul 18 '12 at 03:38

2 Answers2

2

There is not a lot of context here, but if I understand correctly it appears that you have something that needs to happen when the form loads and it might take a long time. You are trying to do this in the paint event because you want to make sure that the user sees something while whatever is loading completes.

Is that assessment correct?

If so, I recommend that you consider the BackgroundWorker class as it will let you do the expensive 'loading' you discuss while keeping the UI responsive.

The example with the documentation does a great job so I'll not write another sample here...

BackgroundWorker Class

Chris

Chris Keller
  • 235
  • 3
  • 9
  • Hi Chris, it's customary in StackOverflow answers to include a summary of the contents of a link or the highlights that specifically answer the question. The goal of SE sites is to become a resource of knowledge, of answers, for years to come. With a link-only answer, the op must dig through another resource to locate an answer he/she might not be sure about. Most importantly, if your link were to ever break, your answer is useless for anyone who visits this page in the future. Consider making an [edit] to your answer to add more details. Good luck! – Jeremy Thompson Jul 18 '12 at 04:10
  • Hi, I actually looked at BackgroundWorker, however, as I am loading alot of stuff into the members in my form, this cannot be done directly, since the threads can't access the member directly, and there has to be too much work to get it working. – ChangYou Wong Jul 18 '12 at 04:15
  • 1
    @JeremyThompson noted. I appreciate you taking the time to make me aware of the oversight and the reasoning behind the recommendation. Thank you! – Chris Keller Jul 18 '12 at 06:47
0

DoEvent

As per mentioned by Jeremy Thompson, many thanks

Though I need to wait 2 days to be able to accept this answer.