Click here to Skip to main content
12,884,480 members (32,350 online)
Rate this:
Please Sign up or sign in to vote.
See more: C#

I am launching a search just after starting a form (initial parameters and so on).
My problem is that the form is not shown open until the search is finished.

I would like to open the form window and show parameters and so before launching the search, just to show the user that something is going on.

I have tried with a button and generating the button click event after opening the form, but it does not work in the way that I expected (just the same result).

The refresh (this.Refresh();) does not work either.

Any idea about how to program that?

Thank you in advance.

Posted 11-Feb-13 4:25am
Fred Flams 11-Feb-13 10:50am
Do use the "Load" event of your form to start the search ?
If so, you should try to start your search process in a background thread, that should help show your form.
Rate this: bad
Please Sign up or sign in to vote.

Solution 1

There are a couple of ways to do this: clearly the nicest from the user perspective is to do it the "proper" way - by moving the time consuming operation into a BackgroundWorker thread and showing the progress.

However, you can show that something has happened by doing it in the Form.Shown event rather than in the Load event or in the constructor. Probably, it won't be very good, unless the search takes very little time, and the controls on the form will not be painted until the shown event (and all other non-background events) have finished processing - Paint is a low priority operation and doesn't happen until there is nothing else going on.

The other method is to use a timer - start it with a half second delay, and stop it them do the long operation in the event handler.

Both of these will do something, but they are quite nasty from a user POV because they will lock up the UI thread until they finish. A BackgroundWorker is a much better solution, if a small amount of extra work for you.
NeueStudium2012 1-Mar-13 12:15pm
The background worker is the richt solution, but anyway it is not sol useful for me as the application can not continue until the secon process has ended.
It is just a matter of showing to the user that something is going on.
Thank you for the ideas.
Rate this: bad
Please Sign up or sign in to vote.

Solution 2


Leave the initializer alone as they are; so that the basic form initialization will take place first.

Create a timer (set the timer to have enough time to load your form) and start timer in "Form_Load" event.

When the timer ticks on the first time call your search function and disable the timer.

If you want to be more productive, you can make use of the timer to show the elapsed time to the user.

NeueStudium2012 1-Mar-13 12:13pm
Hallo Jegan,

Thank you for your answer. I am using this timer solution, and it works fine.
But I find it not so nice as the Background Worker solution, even thougt it is much simpler to control.

So I am considering to move to the Background worker, event though I do not know if that would pay the work, as the program cannot continue anyway until the second pocess has started.
It is just a matter of not having the user waiting without any notice from the program.

Jegan Thiyagesan 3-Mar-13 15:36pm
Yes! you can use the background worker to start the second process in separate thread and use the background worker progress event to update your progress bar to notify the user. When the background worker sends the work complete event, then the first process can continue with what it was suppose to do.


This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

    Print Answers RSS
Top Experts
Last 24hrsThis month

Advertise | Privacy | Mobile
Web02 | 2.8.170422.1 | Last Updated 11 Feb 2013
Copyright © CodeProject, 1999-2017
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100