Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. Visual Basic
  4. Slow form close that contains a DataGridView with bound combobox columns

Slow form close that contains a DataGridView with bound combobox columns

Scheduled Pinned Locked Moved Visual Basic
helpdebuggingquestionannouncement
7 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • M Offline
    M Offline
    Marcus J Smith
    wrote on last edited by
    #1

    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
    Next

    CType(uxRecordDataGrid.Columns("uxDepartmentNameGrid"), DataGridViewComboBoxColumn).DataSource = Nothing

    For Each departmentNameCell As DataGridViewComboBoxCell In CType(uxRecordDataGrid.Columns("uxDepartmentNameGrid"), DataGridViewComboBoxColumn).Items
    departmentNameCell.DataSource = Nothing
    Next

    CType(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

    D 1 Reply Last reply
    0
    • M Marcus J Smith

      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
      Next

      CType(uxRecordDataGrid.Columns("uxDepartmentNameGrid"), DataGridViewComboBoxColumn).DataSource = Nothing

      For Each departmentNameCell As DataGridViewComboBoxCell In CType(uxRecordDataGrid.Columns("uxDepartmentNameGrid"), DataGridViewComboBoxColumn).Items
      departmentNameCell.DataSource = Nothing
      Next

      CType(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

      D Offline
      D Offline
      Dave Kreskowiak
      wrote on last edited by
      #2

      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...

      M 1 Reply Last reply
      0
      • D Dave Kreskowiak

        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...

        M Offline
        M Offline
        Marcus J Smith
        wrote on last edited by
        #3

        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)

        D 1 Reply Last reply
        0
        • M Marcus J Smith

          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)

          D Offline
          D Offline
          Dave Kreskowiak
          wrote on last edited by
          #4

          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...

          L 1 Reply Last reply
          0
          • D Dave Kreskowiak

            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...

            L Offline
            L Offline
            Luc Pattyn
            wrote on last edited by
            #5

            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


            D M 2 Replies Last reply
            0
            • L Luc Pattyn

              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


              D Offline
              D Offline
              Dave Kreskowiak
              wrote on last edited by
              #6

              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...

              1 Reply Last reply
              0
              • L Luc Pattyn

                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


                M Offline
                M Offline
                Marcus J Smith
                wrote on last edited by
                #7

                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)

                1 Reply Last reply
                0
                Reply
                • Reply as topic
                Log in to reply
                • Oldest to Newest
                • Newest to Oldest
                • Most Votes


                • Login

                • Don't have an account? Register

                • Login or register to search.
                • First post
                  Last post
                0
                • Categories
                • Recent
                • Tags
                • Popular
                • World
                • Users
                • Groups