ddivita
Member
- Joined
- May 7, 2008
- Messages
- 19
- Programming Experience
- 10+
I am writing an application that will require the use of threads. I am not entirely sure how to go about setting it up and know little about threading. I need to update my UI when a thread is finished processing and have the ability to cancel the entire process at anytime. I also do not want a new thread to start until the previous thread and process have completed. The image processing I am doing is quite intense and only one instance can run at a time. I have read about thread Pool, but it has been said not to use it if your process runs for a long time. Here is the flow of the piece I need to add threading to:
A collection of images as iList(ofT) - imageCollection
A progress indicator
A listView that will display the results for each images processed
A button on the form to cancel the process
There is an external application I need to call using the Process.Start() method. Unfortunately, I have to do it this way. The application is from a 3rd party vendor we use.
Pseudo Code:
A collection of images as iList(ofT) - imageCollection
A progress indicator
A listView that will display the results for each images processed
A button on the form to cancel the process
There is an external application I need to call using the Process.Start() method. Unfortunately, I have to do it this way. The application is from a 3rd party vendor we use.
Pseudo Code:
VB.NET:
Public sub ProcessImages()
For each image as ImageObject in imageCollection
‘Add this process to a thread
ProcessWorker(image)
When ProcessWorker is complete Update the ListView and Progress bar
Next
End Sub
Private Sub ProcessWorker(image as ImageObject)
Dim imageProcess as new Process = Process.Start(“theAppToRun”,image.name)
imageProcess.start()
‘This line usually hangs the whole system so I usually comment it out
‘imagePorcess.WaitForExit
End Sub
Private Sub btnCancel_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnCancel.Click
KillAllProcessesAndThreads
End Sub
Last edited by a moderator: