I have a vb.net 2.0 program, that has a batch/queue routine to execute tasks that take a long while. One of the tasks is “upload to ftp” of large files. The queue is started by the user clicking the “start” button, and then a for-loop just runs over each batch item, and does whatever it needs.
Now I want to implement a “cancel queue execution” button. The button should be clickable (the gui mustn’t be blocked by the queue being executed), and the button should stop the current queue action (I don’t care about rollback of previously executed tasks).
I guess I need separate threads and some kind of notification scheme, but at what point should I check if the notification is sent? In the for-loop of the queue? But then the user would have to wait for the full upload of the file before the break, which is not what he wants. In the “file upload” method? That’s putting too much code in one method, I feel intuitively.
I also need to do some cleanup of the current batch item’s actions (like delete the partially uploaded file), so that has to be factored in somewhere too.
Any suggestions in high-level code or with examples? Thanks in advance!
Threads??????? your problem can be solved by using “BackgroundWorker”. I really love it, it made such tasks like a breeze..
Try these links for more info:
http://msdn.microsoft.com/en-us/library/8xs8549b.aspx
http://msdn.microsoft.com/en-us/library/system.componentmodel.backgroundworker.aspx
Regards.