Abort a procedure
-
Thursday, May 17, 2012 7:46 PMWhat is the best way to code in VB an Abort procedure when a currently executing procedure is "taking too long" to complete?
All Replies
-
Thursday, May 17, 2012 7:49 PM
What is the best way to code in VB an Abort procedure when a currently executing procedure is "taking too long" to complete?
Slade,
What sort of procedure do you mean? If you're talking about a single process, then you can't (that I'm aware of), but if it's broken into steps, you certainly can.
Is this in a backgroundworker?
Please call me Frank :)
- Marked As Answer by Shanks ZenMicrosoft Contingent Staff, Moderator Wednesday, May 30, 2012 8:34 AM
-
Thursday, May 17, 2012 8:07 PM
Frank,
Thanks for your quick reply.
Yes, I think I do mean a single process, which, if "working", the user would not want to interrupt. I sort of envisioned a form appearing during execution with a button labeled "Abort", displayed using the Show method. The user would press the button and some sort of event would occur which would stop the execution of the process. I obviously would strategically place it somewhere in the procedure where I anticipated the user would get "fed up", with an If statement based on the DialogResult of the form. I guess this would make the abort part of the process. Did I just answer my own question? If so, thanks for listening. If not, please explain further.............
I don't know what a backgroundworker is, so I'll say no.........
-
Thursday, May 17, 2012 8:13 PM
Frank,
Thanks for your quick reply.
Yes, I think I do mean a single process, which, if "working", the user would not want to interrupt. I sort of envisioned a form appearing during execution with a button labeled "Abort", displayed using the Show method. The user would press the button and some sort of event would occur which would stop the execution of the process. I obviously would strategically place it somewhere in the procedure where I anticipated the user would get "fed up", with an If statement based on the DialogResult of the form. I guess this would make the abort part of the process. Did I just answer my own question? If so, thanks for listening. If not, please explain further.............
I don't know what a backgroundworker is, so I'll say no.........
Last things first: If it's a long-running process, it should be on another thread so that it's not making the UI thread (the user's interface) "dead". Either way though, if the process doesn't have events - then to my knowledge it can't be stopped until it's done.
Maybe we'll both learn something here if someone chimes in with "oh sure it can be!"
:)
Please call me Frank :)
-
Friday, May 18, 2012 5:36 AM
Then first set your process in a background worker it is very easy to do. create a new project and do this sample on the page before you start copy and pasting.
http://msdn.microsoft.com/en-us/library/system.componentmodel.backgroundworker.aspx
Success
Cor- Marked As Answer by Shanks ZenMicrosoft Contingent Staff, Moderator Wednesday, May 30, 2012 8:34 AM

