Click here to Skip to main content
15,910,981 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have an app that continues to have it's process running even after the user has closed out of it. My project settings are for a single instance application, to startup on a form called Process.vb (the only form in the app), and the Shutdown mode is When startup form closes.

There is a lot of code, so I thought I'd just explain the basics of what it's doing and hopefully someone can point me to something I haven't thought of...

The process form has a few input controls and one button. The on_click of the button will package the input control data into a class and call a backgroundworker async passing the packaged data to it so as to avoid cross threading. The do_work of the background worker calls methods that access a database. It also calls methods that get FileInfo and DirectoryInfo objects and use System.IO to move files around and a StreamReader used to determine the number of pages in a PDF file. The background worker also reports progress. When finished a string with information about how many files were moved is created and set as the backgroundworker's result.

If I run my app and don't press the button everything closes properly. So there must be something in the backgroundworker that is still open or running that I haven't closed properly, but I can't figure out what. I've gone back and made sure all database controls get disposed and connections get closed. My StreamReader object gets closed and disposed. I couldn't find a way to do any other disposing on the FileInfo objects. I also tried using Application.Exit in a button instead of the form closing and still have the same issue.

Does anyone have any suggestions for common things that do not get disposed properly, or a way to debug and find out what I missed? Any help would be appreciated. Thanks.
Posted
Updated 3-Dec-10 10:14am
v2
Comments
fjdiewornncalwe 3-Dec-10 12:11pm    
Are you manually disposing all the background worker objects when you try to close. It may just be that there is something that is keeping that thread alive even when the parent is closed.
Kschuler 3-Dec-10 12:16pm    
I did try backgroundworker.Dispose() in the FormClosing event....it didn't work.
wizardzz 3-Dec-10 12:26pm    
Do you call any outside processes?
fjdiewornncalwe 3-Dec-10 12:26pm    
Does it continue to run for an indeterminate amount of time, or does it eventually quit on its own?
Kschuler 3-Dec-10 12:30pm    
I do not call any outside processes. I haven't let it run for very long to see if it quits on it's own, I'll give it a try and see.

Are you calling CancelAsync for the background worker?
 
Share this answer
 
Comments
Kschuler 3-Dec-10 13:33pm    
No. I left the backgroundworker property WorkerSupportsCancellation set to false and do not program for cancels.
Finally found it. It was a problem when accessing the database to update some data that was buried several methods deep. I forgot to close an IBM.Data.DB2.iSeries.iDB2DataReader object after using it to get a schema table.

VB
 Dim rdrSchema As IBM.Data.DB2.iSeries.iDB2DataReader
 Dim cmdSel As New IBM.Data.DB2.iSeries.iDB2Command

 'Retrieve File Schema
 cmdSel = inDaFile.SelectCommand
 rdrSchema = cmdSel.ExecuteReader(CommandBehavior.KeyInfo)
 dtSchema = rdrSchema.GetSchemaTable

'adding this statement fixed my issue
 rdrSchema.Close()


Thanks to those who suggested possible problems!
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900