p2p.wrox.com Forums

p2p.wrox.com Forums (http://p2p.wrox.com/index.php)
-   VB How-To (http://p2p.wrox.com/forumdisplay.php?f=78)
-   -   Show Form2, only then run Routine1 (http://p2p.wrox.com/showthread.php?t=66105)

peterasimpson February 22nd, 2008 10:24 AM

Show Form2, only then run Routine1
 
Hello,
I was wondering how can I press Button1 in VB.NET 2005 and get my software to 1st show Form2 and then run Routine1, but only run Routone1 after Form2 is shown on the screen.

1. Show Form2
2. Run a Routine1.

The problem I'm having is that when I press Button1 it runs 1 & 2 but shows Form2 after it has finished processing Routine1.

Actually Form2 is an animated timer that says 'Please wait, processing your data'. Routine1 is 4 very complicated cross table SQL queries that takes about 9 seconds to complete.

I basically want to show Form2 then run Routine1 on one button press and not two button presses.

Any help would be greatful as it does not matter how much I try, Form2 only ever shows 9 seconds after I press Button1. 9 seconds is the amount of time it takes to process the SQL queries.

Thank you for any help in advance.

prabodh_mishra March 18th, 2008 06:43 AM

try calling Routine1 from within Form2


Prabodh

peterasimpson March 18th, 2008 07:02 AM

Hello,
I tried that and it didnt word. I ended up runing the timer as the last call thus running a seperate routine.

Simplicity is the key

BrianWren March 18th, 2008 10:56 AM

There are several things a form needs to do to be fully loaded and displayed. Most of those things raise events (Load, Activate, Resize, etc.)

You often can have one of these events change the value of a variable that some other process checks before running, thereby being able to cause it to "wait."

But since your routine takes so long to run, it seems that the form should be able to get its act together while the routine is running.

Many types of action tie up the processor, so that the screen effectively "freezes" until the action is done. In VB6 the way to overcome that is to add DoEvents to the routine. This is an explicit command to release the processor to service pending lower-priority acttions (like updating the screen).

In .NET use Application.DoEvents().

So what you would do is run the components in the order you indicated above. In routine 1, upon entry run DoEvents, and if yo uhave a loop in the routine put a DoEvents where it will run regularly. If no loop, sprinkle DoEvents throughout the routine.

BTW, it’s sep[u]a</u>rate, not sep[u]e</u>rate...

peterasimpson April 8th, 2008 02:44 PM

I'll try that next week. Yes 'separate' was just a little typo error.

Simplicity is the key

Raghavendra_Mudugal April 29th, 2008 06:47 AM

Hello Peter;

to state it- its something like this... say you have to update some 1000 records and when the update is going on-behind process, you have to show a form saying "process going on, please wait" and then process is completed automatically the form2 needs to get closed, so user comes to know the process is done.

is that correct?

If yes, to make it simple...
- u click button1 (process starts)
- u load form2 (animation)
- then add one timer which will starts automatically after the load of the form2
- then in the time after certain interval stop the timer and call the Routine1 in timer event.
- This will load the form2 first and calls the main routine.

look into this example of vb6, link; http://in.geocities.com/raghavendra_...ainRoutine.zip which will show these steps in action.

Hope this helps.


With Regards,
Raghavendra Mudugal


All times are GMT -4. The time now is 01:32 PM.

Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.