Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: C#
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 11-Feb-13 4:25am
Comments
Fred Flams at 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
good
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.
  Permalink  
Comments
NeueStudium2012 at 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
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 2

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
  Permalink  
Comments
NeueStudium2012 at 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 at 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)

  Print Answers RSS
0 Maciej Los 589
1 OriginalGriff 419
2 CPallini 205
3 RyanDev 175
4 Sergey Alexandrovich Kryukov 170
0 OriginalGriff 5,649
1 Sergey Alexandrovich Kryukov 4,783
2 Peter Leow 2,954
3 Maciej Los 2,689
4 DamithSL 2,465


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