Click here to Skip to main content
15,889,462 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hallo,

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.

David.
Posted
Comments
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.

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.
 
Share this answer
 
Comments
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.
David
Hi
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.


Regards
Jegan
 
Share this answer
 
Comments
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.

BR
David
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.

Jegan

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



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900