End Threadpool queued Items

leedo2k

Active member
Joined
Nov 9, 2006
Messages
28
Programming Experience
Beginner
Hi,
I am using the threadpool to queue threads that do network file upload. Now, the problem is that every time I close my application while the threads are running in the back ground, I expectedly get some nasty errors. Now how can I decently and gracefully shut down my application or in other words end all running threads before exiting the application?

Thanks
 
Hi,

I am using the following code:

VB.NET:
 For Each file As String In IO.Directory.GetFiles(LocalFolderPath)

            DMPUploadProgress = Interlocked.Increment(DMPUploadProgress)

            Threading.ThreadPool.QueueUserWorkItem(New _  WaitCallback(AddressOf  UploadFile), _
New String() {file, DMPip, Targetstorage})

        Next file

I am not getting errors, I am still looking for a way to end the threads I throw to the thread pool in case the user wishes to abort.
 
Now, the problem is that every time I close my application while the threads are running in the back ground, I expectedly get some nasty errors.
I am not getting errors
:confused:

Background threads do not prevent your process exiting, so if exiting without cleaning up your thread will not leave data in an invalid state then you have nothing to worry about. If you specifically need to cancel the background operation then you can explicitly create the Thread object and call its Abort method or else use a BackgroundWorker and call CancelAsync.
 
Back
Top