Slow form close that contains a DataGridView with bound combobox columns
-
I have a form that displays a list of records in a DataGridView. The recordset in question is about 9,000 records. I know that is a lot but is required by the application. The problem I am experiencing is the form closing. I call the dispose methods of some class level variables which slows the close down quite a bit. I have seen it take anywhere from 10 seconds to 2+ minutes. This is a hinderence to the users of the application. I have written some Debug.Writeline() statements with timestamps to see how long each dispose call is taking. The slowdown is on my unfiltered datatables which are bound to the DGV combobox columns. A filtered version is bound to each individual cell that is edited but after the edit the original unfiltered datatable is bound to the cell again. The unfiltered tables only contain 20 or so records but are taking 8+ seconds minimum to clear and dispose compared to the milliseconds it is taking all of the other tables. Here is my current iteration of the close (please note that the original call was only to dispose of the _Utilities object, I have added the other calls to try tracking down the issue):
uxRecords.Clear()
uxRecordsBindingSource.DataSource = Nothing
uxRecordDataGrid.DataSource = Nothing
uxRecordDataGrid.Rows.Clear()CType(uxRecordDataGrid.Columns("uxVersionNameGrid"), DataGridViewComboBoxColumn).DataSource = Nothing
For Each versionNameCell As DataGridViewComboBoxCell In CType(uxRecordDataGrid.Columns("uxVersionNameGrid"), DataGridViewComboBoxColumn).Items
versionNameCell.DataSource = Nothing
NextCType(uxRecordDataGrid.Columns("uxDepartmentNameGrid"), DataGridViewComboBoxColumn).DataSource = Nothing
For Each departmentNameCell As DataGridViewComboBoxCell In CType(uxRecordDataGrid.Columns("uxDepartmentNameGrid"), DataGridViewComboBoxColumn).Items
departmentNameCell.DataSource = Nothing
NextCType(uxRecordDataGrid.Columns("uxSizeGrid"), DataGridViewComboBoxColumn).DataSource = Nothing
For Each sizeCell As DataGridViewComboBoxCell In CType(uxRecordDataGrid.Columns("uxSizeGrid"), DataGridViewComboBoxColumn).Items
sizeCell .DataSource = Nothing
Next_Utilities.Dispose()
The _Utilities.Dispose call disposes of each table and that is where the slowdown is. Everything up to that call occurs within the same second.
CleaKO
"Now, a man would ha
-
I have a form that displays a list of records in a DataGridView. The recordset in question is about 9,000 records. I know that is a lot but is required by the application. The problem I am experiencing is the form closing. I call the dispose methods of some class level variables which slows the close down quite a bit. I have seen it take anywhere from 10 seconds to 2+ minutes. This is a hinderence to the users of the application. I have written some Debug.Writeline() statements with timestamps to see how long each dispose call is taking. The slowdown is on my unfiltered datatables which are bound to the DGV combobox columns. A filtered version is bound to each individual cell that is edited but after the edit the original unfiltered datatable is bound to the cell again. The unfiltered tables only contain 20 or so records but are taking 8+ seconds minimum to clear and dispose compared to the milliseconds it is taking all of the other tables. Here is my current iteration of the close (please note that the original call was only to dispose of the _Utilities object, I have added the other calls to try tracking down the issue):
uxRecords.Clear()
uxRecordsBindingSource.DataSource = Nothing
uxRecordDataGrid.DataSource = Nothing
uxRecordDataGrid.Rows.Clear()CType(uxRecordDataGrid.Columns("uxVersionNameGrid"), DataGridViewComboBoxColumn).DataSource = Nothing
For Each versionNameCell As DataGridViewComboBoxCell In CType(uxRecordDataGrid.Columns("uxVersionNameGrid"), DataGridViewComboBoxColumn).Items
versionNameCell.DataSource = Nothing
NextCType(uxRecordDataGrid.Columns("uxDepartmentNameGrid"), DataGridViewComboBoxColumn).DataSource = Nothing
For Each departmentNameCell As DataGridViewComboBoxCell In CType(uxRecordDataGrid.Columns("uxDepartmentNameGrid"), DataGridViewComboBoxColumn).Items
departmentNameCell.DataSource = Nothing
NextCType(uxRecordDataGrid.Columns("uxSizeGrid"), DataGridViewComboBoxColumn).DataSource = Nothing
For Each sizeCell As DataGridViewComboBoxCell In CType(uxRecordDataGrid.Columns("uxSizeGrid"), DataGridViewComboBoxColumn).Items
sizeCell .DataSource = Nothing
Next_Utilities.Dispose()
The _Utilities.Dispose call disposes of each table and that is where the slowdown is. Everything up to that call occurs within the same second.
CleaKO
"Now, a man would ha
Why are you calling Dispose on your DataTables? You don't have to unless you've created your own DataTable objects and there is stuff that needs to be freed/done before your DataTable object is destroyed. The tables will get Destroyed/Collected by the GC when they go out of scope automatically. Unless you have a valid reason to, by default, there is no need to call Dipose on DataTables.
A guide to posting questions on CodeProject[^]
Dave Kreskowiak Microsoft MVP Visual Developer - Visual Basic
2006, 2007, 2008
But no longer in 2009... -
Why are you calling Dispose on your DataTables? You don't have to unless you've created your own DataTable objects and there is stuff that needs to be freed/done before your DataTable object is destroyed. The tables will get Destroyed/Collected by the GC when they go out of scope automatically. Unless you have a valid reason to, by default, there is no need to call Dipose on DataTables.
A guide to posting questions on CodeProject[^]
Dave Kreskowiak Microsoft MVP Visual Developer - Visual Basic
2006, 2007, 2008
But no longer in 2009...The DataTables that I am disposing of are instantiated at the class level for specific data. It is not the DataSet bound DataTables that I am disposing of, it is those individual datatables. Didnt I have a discussion with you a few years ago where you said to dispose of anything that implements IDisposable?
CleaKO
"Now, a man would have opened both gates, driven through and not bothered to close either gate." - Marc Clifton (The Lounge)
-
The DataTables that I am disposing of are instantiated at the class level for specific data. It is not the DataSet bound DataTables that I am disposing of, it is those individual datatables. Didnt I have a discussion with you a few years ago where you said to dispose of anything that implements IDisposable?
CleaKO
"Now, a man would have opened both gates, driven through and not bothered to close either gate." - Marc Clifton (The Lounge)
I can't remember what I had for lunch yesterday, let alone who I talked to about what a few years ago. ;) Probably so, though, my position has changed on various aspects of the .NET Framework over the years. It used to be that it was suggested you called Dispose on anything implementing IDisposable, but now, that's changed. You should know WHY you're calling Dispose on an object and understand that an implementation of it may only be there to let you override it in your own inherited classes.
A guide to posting questions on CodeProject[^]
Dave Kreskowiak Microsoft MVP Visual Developer - Visual Basic
2006, 2007, 2008
But no longer in 2009... -
I can't remember what I had for lunch yesterday, let alone who I talked to about what a few years ago. ;) Probably so, though, my position has changed on various aspects of the .NET Framework over the years. It used to be that it was suggested you called Dispose on anything implementing IDisposable, but now, that's changed. You should know WHY you're calling Dispose on an object and understand that an implementation of it may only be there to let you override it in your own inherited classes.
A guide to posting questions on CodeProject[^]
Dave Kreskowiak Microsoft MVP Visual Developer - Visual Basic
2006, 2007, 2008
But no longer in 2009...Dave Kreskowiak wrote:
I can't remember what I had for lunch yesterday
Turkey leftovers with fried onion rings on the side?
Dave Kreskowiak wrote:
it was suggested you called Dispose on anything implementing IDisposable, but now, that's changed.
That is horrible. It used to be simple: it is available, there may or may not be unmanaged resources involved (and that may change from one version to the next), so call Dispose(). As to the original question: wouldn't it be wise, and maybe even help, to remove the data binding first? :)
Luc Pattyn [Forum Guidelines] [Why QA sucks] [My Articles]
I only read code that is properly indented, and rendered in a non-proportional font; hint: use PRE tags in forum messages
-
Dave Kreskowiak wrote:
I can't remember what I had for lunch yesterday
Turkey leftovers with fried onion rings on the side?
Dave Kreskowiak wrote:
it was suggested you called Dispose on anything implementing IDisposable, but now, that's changed.
That is horrible. It used to be simple: it is available, there may or may not be unmanaged resources involved (and that may change from one version to the next), so call Dispose(). As to the original question: wouldn't it be wise, and maybe even help, to remove the data binding first? :)
Luc Pattyn [Forum Guidelines] [Why QA sucks] [My Articles]
I only read code that is properly indented, and rendered in a non-proportional font; hint: use PRE tags in forum messages
Luc Pattyn wrote:
Turkey leftovers with fried onion rings on the side?
I hate onion rings... -bleck-
Luc Pattyn wrote:
As to the original question: wouldn't it be wise, and maybe even help, to remove the data binding first?
Maybe. The only way to tell would be to try it. I'm just not that into testing it myself this week.
A guide to posting questions on CodeProject[^]
Dave Kreskowiak Microsoft MVP Visual Developer - Visual Basic
2006, 2007, 2008
But no longer in 2009... -
Dave Kreskowiak wrote:
I can't remember what I had for lunch yesterday
Turkey leftovers with fried onion rings on the side?
Dave Kreskowiak wrote:
it was suggested you called Dispose on anything implementing IDisposable, but now, that's changed.
That is horrible. It used to be simple: it is available, there may or may not be unmanaged resources involved (and that may change from one version to the next), so call Dispose(). As to the original question: wouldn't it be wise, and maybe even help, to remove the data binding first? :)
Luc Pattyn [Forum Guidelines] [Why QA sucks] [My Articles]
I only read code that is properly indented, and rendered in a non-proportional font; hint: use PRE tags in forum messages
I am working on that path now. I tried simply setting the
DataSource = Nothing
for the columns, datagridview, and cells within the combobox columns. Apparently that isnt working good enough because the dispose is forcing the grid to go through and remove bindings which is raising events which is slowing down the dispose.
CleaKO
"Now, a man would have opened both gates, driven through and not bothered to close either gate." - Marc Clifton (The Lounge)