943,648 Members | Top Members by Rank

Ad:
You are currently viewing page 1 of this multi-page discussion thread
Feb 14th, 2009
0

STOP a process in between .....

Expand Post »
hi,
i've created a Form1 which contains a long running process. But i want an feature that will help the user to stop the running process in between, when i click a Button or some other control.

How is it possible?
Similar Threads
Reputation Points: 26
Solved Threads: 0
Junior Poster in Training
RahulV is offline Offline
92 posts
since Jun 2007
Feb 14th, 2009
0

Re: STOP a process in between .....

Also the problem is that my Form1 which runs the process goes like disabled (automatically), ..... thats because, .... u can imagine because its a long process.

so im not able access the controls on the Form1.


PLS help !!!
Reputation Points: 26
Solved Threads: 0
Junior Poster in Training
RahulV is offline Offline
92 posts
since Jun 2007
Feb 15th, 2009
0

Re: STOP a process in between .....

Hi, use

DoEvents function so that other process get chance. This function helps to disable your form.

Example
VB Syntax (Toggle Plain Text)
  1. Dim bStop As Boolean
  2.  
  3. Private Sub cmdProcess_Click()
  4. Do While bStop <> True
  5. '
  6. ' Long Process
  7. '
  8. CurrentX = 0
  9. CurrentY = 0
  10. Cls
  11. Print Time
  12. DoEvents
  13. Loop
  14. bStop = False
  15. End Sub
  16.  
  17. Private Sub cmdStop_Click()
  18. bStop = True
  19. End Sub
Reputation Points: 44
Solved Threads: 101
Posting Pro
selvaganapathy is offline Offline
547 posts
since Feb 2008
Feb 15th, 2009
0

Re: STOP a process in between .....

If it is a system call (such as shell, or wsh.run) and it is blocking (ie, the program is waiting for shell or wsh.run to finish the externally running program), you need a much more complicated method involving things like waitforsingleobject...
Team Colleague
Reputation Points: 361
Solved Threads: 214
Taboo Programmer
Comatose is offline Offline
2,413 posts
since Dec 2004
Feb 16th, 2009
0

Re: STOP a process in between .....

Hi, use

DoEvents function so that other process get chance. This function helps to disable your form.

Example
VB Syntax (Toggle Plain Text)
  1. Dim bStop As Boolean
  2.  
  3. Private Sub cmdProcess_Click()
  4. Do While bStop <> True
  5. '
  6. ' Long Process
  7. '
  8. CurrentX = 0
  9. CurrentY = 0
  10. Cls
  11. Print Time
  12. DoEvents
  13. Loop
  14. bStop = False
  15. End Sub
  16.  
  17. Private Sub cmdStop_Click()
  18. bStop = True
  19. End Sub

Sorry this did not work i told u that, mu Form1 gets disabled, thats normal when there's some long process is taking place. So im not getting access to the cmdButton (to click).
Reputation Points: 26
Solved Threads: 0
Junior Poster in Training
RahulV is offline Offline
92 posts
since Jun 2007
Feb 16th, 2009
0

Re: STOP a process in between .....

Click to Expand / Collapse  Quote originally posted by Comatose ...
If it is a system call (such as shell, or wsh.run) and it is blocking (ie, the program is waiting for shell or wsh.run to finish the externally running program), you need a much more complicated method involving things like waitforsingleobject...

Im not running any other program or shell.
Its just that the Form1 is processing a long process. Like suppose counting to 1000crores or more.
Last edited by RahulV; Feb 16th, 2009 at 2:58 pm.
Reputation Points: 26
Solved Threads: 0
Junior Poster in Training
RahulV is offline Offline
92 posts
since Jun 2007
Feb 16th, 2009
0

Re: STOP a process in between .....

then doevents should work just fine.... somewhere when your form1 is doing processing... probably in some kind of do loop or while loop or for loop, simply stick a doevents.
vb Syntax (Toggle Plain Text)
  1. for i = 0 to 1000000
  2. retval = i * i
  3. doevents
  4. next i
Last edited by Comatose; Feb 16th, 2009 at 3:53 pm.
Team Colleague
Reputation Points: 361
Solved Threads: 214
Taboo Programmer
Comatose is offline Offline
2,413 posts
since Dec 2004
Feb 18th, 2009
0

Re: STOP a process in between .....

Click to Expand / Collapse  Quote originally posted by Comatose ...
then doevents should work just fine.... somewhere when your form1 is doing processing... probably in some kind of do loop or while loop or for loop, simply stick a doevents.
vb Syntax (Toggle Plain Text)
  1. for i = 0 to 1000000
  2. retval = i * i
  3. doevents
  4. next i
Sorry it did not work for me.....
Pls can anyone help me with this.

can creating thread help with this?
Reputation Points: 26
Solved Threads: 0
Junior Poster in Training
RahulV is offline Offline
92 posts
since Jun 2007
Feb 18th, 2009
0

Re: STOP a process in between .....

I'm going to need to see your code then, in order to be able to troubleshoot this further.
You can not create a thread in Visual Basic 4/5/6. Doevents is only a partial fix to your problem. Doevents tells VB that a long ass loop is going on, and that it needs to do other stuff too, like handle mouse clicks. So, just for example, make a form and put 2 buttons on it....in button1, put this:
vb Syntax (Toggle Plain Text)
  1. while 1 = 1
  2. x = 200 * 200
  3. wend
Then, in button2, put this:
vb Syntax (Toggle Plain Text)
  1. end
Now run the code, and click button1. Now Try to click button2. Nice Huh? Now modify button1 to have this:
vb Syntax (Toggle Plain Text)
  1. while 1 = 1
  2. x = 200 * 200
  3. doevents
  4. wend
Run the code, click button1, now click button2..... oh wow. Big difference.
Last edited by Comatose; Feb 18th, 2009 at 9:29 am.
Team Colleague
Reputation Points: 361
Solved Threads: 214
Taboo Programmer
Comatose is offline Offline
2,413 posts
since Dec 2004
Feb 18th, 2009
0

Re: STOP a process in between .....

@ Comatose

Okay!
that does work.

but in ur example u had written
Visual Basic 4 / 5 / 6 Syntax (Toggle Plain Text)
  1. End
statement for Button2 and that ends the whole program, instead i want to just end the running sub-procedure or the loop.

You have any other idea on this?
Reputation Points: 26
Solved Threads: 0
Junior Poster in Training
RahulV is offline Offline
92 posts
since Jun 2007

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in Visual Basic 4 / 5 / 6 Forum Timeline: SSTAB problem with TAB2
Next Thread in Visual Basic 4 / 5 / 6 Forum Timeline: access events of form in UserControl





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC