Results 1 to 21 of 21

Thread: [DONE FOR NOW] Weird Screen Redraw Issue

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Apr 2019
    Location
    Sabattus
    Posts
    234

    [DONE FOR NOW] Weird Screen Redraw Issue

    Something odd is going on with my dropdown menus when i hover over them.
    This only happens when I have this datagridview on the screen.

    If I have 31k records loaded and I hover over a menu.... it doesn't finish drawing the menu for about 5 seconds.

    But, if a load only 200 records.... the menu redraws immediately.

    What is happening to the painting of my screen because of the datagridview.

    Like I said, it only does this when I have the datagridview visible and loaded with a lot of records.


    And yes, I do close the sqlite database connection after loading.

    This does this even after 10 minutes after loading records.

    It seems to be a screen redraw issue.


    But, how do fix this? Or can I?

    See below screen

    Name:  biblenotes5.jpg
Views: 424
Size:  16.7 KB


    Thanks
    Last edited by pixelink; Jul 25th, 2020 at 11:43 AM.
    Can't Type - Forgetful - Had Stroke = Forgive this old man!
    Website: https://pixelinkmedia.wixsite.com/frankhilton
    VSCOMM 2022 • LAZARUS 2.2.0 • Win10 • 16G RAM • Nvida GForce RTX 2060

  2. #2
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    110,350

    Re: Weird Screen Redraw Issue

    Is it every menu item? Is there anything at all out of the ordinary about that menu?

  3. #3

    Thread Starter
    Addicted Member
    Join Date
    Apr 2019
    Location
    Sabattus
    Posts
    234

    Re: Weird Screen Redraw Issue

    All menus... and like I said, its worst with the more records that are loaded in the datagridview.

    I have many tabs. So, it doesn't do it if I am on the "Chapter" tab that only has a richtextbox control.... only on a tab that has a datagridview.
    Can't Type - Forgetful - Had Stroke = Forgive this old man!
    Website: https://pixelinkmedia.wixsite.com/frankhilton
    VSCOMM 2022 • LAZARUS 2.2.0 • Win10 • 16G RAM • Nvida GForce RTX 2060

  4. #4
    Super Moderator Shaggy Hiker's Avatar
    Join Date
    Aug 2002
    Location
    Idaho
    Posts
    39,047

    Re: Weird Screen Redraw Issue

    When the menu opens, does it extend over the area of the datagridview?

    What I am suspecting is that opening the menu is causing the grid to redraw, and that is slow for some reason. It can't just be redrawing the visible area, though, because you don't have 31,000 records visible. It may not be redrawing that is the issue, it may be some other kind of recalculation on the DGV. The point is that the fact that it isn't slow with 200, but is slow with 31,000 makes it sound like you are paying a per record cost. The cost per record is tiny, so 200 times that cost is too short to notice, but 31,000 times that cost is noticeable amounts of time. Redrawing is the most common cause of such a slowdown, but the DGV should only be redrawing the visible area, at worst, so something is getting triggered.
    My usual boring signature: Nothing

  5. #5
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    110,350

    Re: Weird Screen Redraw Issue

    It's time to be a developer. Create a new project with a grid and a menu. Load the grid with lots of records and open the menu. Does it do the same thing? If not then it's something specific to that project. Time to start making the test project more like the original project until you find the point at which it breaks. If it never does then maybe something is corrupt in the original project. It can happen with seemingly no explanation.

  6. #6

    Thread Starter
    Addicted Member
    Join Date
    Apr 2019
    Location
    Sabattus
    Posts
    234

    Re: Weird Screen Redraw Issue

    Quote Originally Posted by Shaggy Hiker View Post
    When the menu opens, does it extend over the area of the datagridview?

    What I am suspecting is that opening the menu is causing the grid to redraw, and that is slow for some reason. It can't just be redrawing the visible area, though, because you don't have 31,000 records visible. It may not be redrawing that is the issue, it may be some other kind of recalculation on the DGV. The point is that the fact that it isn't slow with 200, but is slow with 31,000 makes it sound like you are paying a per record cost. The cost per record is tiny, so 200 times that cost is too short to notice, but 31,000 times that cost is noticeable amounts of time. Redrawing is the most common cause of such a slowdown, but the DGV should only be redrawing the visible area, at worst, so something is getting triggered.
    No some menus do not display over the grid.
    Can't Type - Forgetful - Had Stroke = Forgive this old man!
    Website: https://pixelinkmedia.wixsite.com/frankhilton
    VSCOMM 2022 • LAZARUS 2.2.0 • Win10 • 16G RAM • Nvida GForce RTX 2060

  7. #7

    Thread Starter
    Addicted Member
    Join Date
    Apr 2019
    Location
    Sabattus
    Posts
    234

    Re: Weird Screen Redraw Issue

    Quote Originally Posted by jmcilhinney View Post
    It's time to be a developer. Create a new project with a grid and a menu. Load the grid with lots of records and open the menu. Does it do the same thing? If not then it's something specific to that project. Time to start making the test project more like the original project until you find the point at which it breaks. If it never does then maybe something is corrupt in the original project. It can happen with seemingly no explanation.
    yeah... i was heading this way if i don't get more info
    Can't Type - Forgetful - Had Stroke = Forgive this old man!
    Website: https://pixelinkmedia.wixsite.com/frankhilton
    VSCOMM 2022 • LAZARUS 2.2.0 • Win10 • 16G RAM • Nvida GForce RTX 2060

  8. #8

    Thread Starter
    Addicted Member
    Join Date
    Apr 2019
    Location
    Sabattus
    Posts
    234

    Re: Weird Screen Redraw Issue

    I saw some info on stockexchange about double-buffering.... but that had to do with loading speed.

    Will double-buffering help?
    And how do I add double-buffering to all my datagridviews??
    Can't Type - Forgetful - Had Stroke = Forgive this old man!
    Website: https://pixelinkmedia.wixsite.com/frankhilton
    VSCOMM 2022 • LAZARUS 2.2.0 • Win10 • 16G RAM • Nvida GForce RTX 2060

  9. #9
    Super Moderator Shaggy Hiker's Avatar
    Join Date
    Aug 2002
    Location
    Idaho
    Posts
    39,047

    Re: Weird Screen Redraw Issue

    Dobule buffering will not help with this. That has to do with rendering the pixels to the screen. It can make some displays smoother, if the image stutters, but that's not the problem you are dealing with.

    Something you are doing is causing the DGV to take some action per row, from the sound of it. Making up the test project would be a really good way of trying to isolate the problem.
    My usual boring signature: Nothing

  10. #10

    Thread Starter
    Addicted Member
    Join Date
    Apr 2019
    Location
    Sabattus
    Posts
    234

    Re: Weird Screen Redraw Issue

    Okay. Using a test copy.

    I commented out the code that loads the datagridview with 31k records.

    Menus work perfectly when I am on that tab (with empty datagridview)
    However, I do have a few other tabs with a datagridview that only loads 100 records or so. They have a very slight delay in the menus drawing.

    And like I said, if I am on a tab that has no datagridview, there is NO delay in drawing the menu at all

    So, its obvious that the datagrid is doing something that I have not told it to do.

    I am closing the connection and disposing the datadapter (Sqlite) for all my connections

    So, not sure why loading 31k records does this.

    Its not critical, I can live with it.
    I was just wondering if anyone knew off the top of their head whats up.

    I am not using any graphic draws in this app either. Just to rule that out.
    Can't Type - Forgetful - Had Stroke = Forgive this old man!
    Website: https://pixelinkmedia.wixsite.com/frankhilton
    VSCOMM 2022 • LAZARUS 2.2.0 • Win10 • 16G RAM • Nvida GForce RTX 2060

  11. #11
    Super Moderator Shaggy Hiker's Avatar
    Join Date
    Aug 2002
    Location
    Idaho
    Posts
    39,047

    Re: Weird Screen Redraw Issue

    In your test app, do the menus DO anything? If they do, then comment out all of that, as well. You want the menus to do nothing other than open and close, with no click handlers, or any other handler.

    Another point is that it sounds like you cloned your existing application and commented some stuff out for the test. If that's the case, it's not good enough for a true test, since you don't know where the problem lies (or else you'd have it fixed), so you may inadvertently leave something in that you shouldn't. What you should be doing for the test is creating a brand new project of the same type. Add a form, put a DGV on it, add some menus that do nothing, then if all is working (it really should be, with just that little bit), then fill the DGV with the 31K records and see whether or not the behavior is good or bad.
    My usual boring signature: Nothing

  12. #12

    Thread Starter
    Addicted Member
    Join Date
    Apr 2019
    Location
    Sabattus
    Posts
    234

    Re: Weird Screen Redraw Issue

    Yes on the first point... I just copied the project.

    So, I did what you suggested.

    Except i did it in stages.

    1) Removed all code except the code that loads the 31k records; leaving the menu strip (w/no code behind)
    And removed all secondary forms from project

    2) My app has 3 main panels with 4+ tabs on each. (13 in all)
    So, I removed the Right panel, tested... failed
    I removed the middle panel, tested... failed
    Then I removed all the other tabs on the Left panel, tested... failed

    3) Then removed the tab and was left with just the datagridview and the drop down (which I test with and without.

    4) Removed all menu items but one

    So, it still delays.

    See screen... so, it has to be the 31k datagridview because there is nothing left


    Name:  biblenotes6.jpg
Views: 183
Size:  47.8 KB
    Can't Type - Forgetful - Had Stroke = Forgive this old man!
    Website: https://pixelinkmedia.wixsite.com/frankhilton
    VSCOMM 2022 • LAZARUS 2.2.0 • Win10 • 16G RAM • Nvida GForce RTX 2060

  13. #13
    Super Moderator Shaggy Hiker's Avatar
    Join Date
    Aug 2002
    Location
    Idaho
    Posts
    39,047

    Re: Weird Screen Redraw Issue

    I'd go further. It's starting to get interesting, because if you did as you say, you've removed pretty much all the most likely candidates....except one, so before getting to what I was going to suggest:

    1) Where are you loading that DGV? You said you left the code that did that. Where is that code located. The results you are seeing would also happen if you are calling that code FAR more often than you think you are. Putting a breakpoint in that code and seeing that it is hit once and ONLY once, would be the easiest thing to do.

    2) If that doesn't turn up anything, then what I would do is not work with the clone. Create a totally new project, add the menus, then add the DGV, while doing as little copying from the old project as you can bear to do. After all, there are times when "something" happens with a project. Some setting gets set to where you didn't expect, or didn't want. By going with the fresh start, rather than subtracting from the clone, you are starting with a clean slate. There won't be any baggage that you didn't know about.
    My usual boring signature: Nothing

  14. #14

    Thread Starter
    Addicted Member
    Join Date
    Apr 2019
    Location
    Sabattus
    Posts
    234

    Re: Weird Screen Redraw Issue

    Okay... this is strange.

    Woke up this morning... and booted up my PC.
    Ran my test project ("the clone").... and the menus worked perfectly.

    So, I ran my full version with everything... worked perfectly.

    So, it looks like something was running on my PC the entire day.
    Note sure what, nothing happened during the day, no crashes, no ant-virus scan or anything.

    So, it looks like that it was something outside of the app.

    Will have to run my process exploree next time this shows up see if I can see what it is.

    THANKS for Everyone's Help
    Can't Type - Forgetful - Had Stroke = Forgive this old man!
    Website: https://pixelinkmedia.wixsite.com/frankhilton
    VSCOMM 2022 • LAZARUS 2.2.0 • Win10 • 16G RAM • Nvida GForce RTX 2060

  15. #15

    Thread Starter
    Addicted Member
    Join Date
    Apr 2019
    Location
    Sabattus
    Posts
    234

    Re: Weird Screen Redraw Issue

    And FYI...
    Here is the only code I use to load the records (in my test project too)

    It only cycles once... no re-occurrences, even after it has loaded on the screen.

    Code:
    Private Sub Form1_Load(sender As Object, e As EventArgs) Handles Me.Load
            getBible()
    
        End Sub
    
    Sub connect()
            Try
                connection = New SQLiteConnection("Data Source=kjv.db3")
                If connection.State = ConnectionState.Closed Then
                    connection.Open()
                End If
            Catch ex As Exception
                MsgBox("Connection Failed!")
            End Try
        End Sub
    
    
        Sub getBible()
    
            connect()
            Dim da As New SQLiteDataAdapter("select * from main ORDER BY CAST(Book As Integer), CAST(Chapter AS INTEGER), CAST(Verse AS INTEGER)", connection)
            Dim dt As New DataTable
            Dim ds As New DataSet
            da.Fill(ds, "main")
    
            'load bible in dg
            dgBible.DataSource = ds
            dgBible.DataMember = "main"
    
            connection.Clone()
            da.Dispose()
    
        End Sub

    Will this code create a small memory leak throughout the day if I keep running it several times??
    Last edited by pixelink; Jul 25th, 2020 at 08:36 AM.
    Can't Type - Forgetful - Had Stroke = Forgive this old man!
    Website: https://pixelinkmedia.wixsite.com/frankhilton
    VSCOMM 2022 • LAZARUS 2.2.0 • Win10 • 16G RAM • Nvida GForce RTX 2060

  16. #16
    Sinecure devotee
    Join Date
    Aug 2013
    Location
    Southern Tier NY
    Posts
    6,582

    Re: Weird Screen Redraw Issue

    Could have been a resource issue.
    If you have programs running that are leaking resources, then windows pool of resources can get low so programs that need resources can get bogged down during the allocating and releasing of resources. You may have been on the edge of getting an "out of memory" type error, even though the error is really a lack of system resources, not really memory.

    Of course, with a fresh reboot, the pool is full of resources so everything should run smooth until whatever badly managed program(s) chew up resources again, i.e. getting them, but not returning them to the pool when finished with them.

    p.s. didn't notice your last post. I don't know enough about database accesses to say whether there is something culpable there.
    "Anyone can do any amount of work, provided it isn't the work he is supposed to be doing at that moment" Robert Benchley, 1930

  17. #17
    Super Moderator Shaggy Hiker's Avatar
    Join Date
    Aug 2002
    Location
    Idaho
    Posts
    39,047

    Re: Weird Screen Redraw Issue

    There is nothing in that code that seems too out of order. It can be improved in a few small ways, but it shouldn't be causing the problem.

    The only real issue is around the connection. At the end of the getBible method, you call connection.Clone(). Is that a typo? I would expect connection.Close, not Clone. I'm also not sure how SqlLite connections work. You never get rid of the connection, which must be a form level variable. I wouldn't expect that to cause a problem, but only because I'm making a few assumptions that might be unwarranted. Therefore, you might improve on the connection part. After all, you create the connection, then immediately check whether it is closed. It's brand new. It will be in one state or another every time, so why check? You also don't need to open it, because the datatadapter will do that. I don't have an issue with you opening it, though, because I screw that one up routinely. Dataadapters will open closed connections, but creating a datareader won't, so sometimes you do have to open it, while other times you don't, and it's an easy mistake to make. For that reason, I have no issue with always opening it yourself. Still, rather than that method, how about this:
    Code:
    Using connection As New SQLiteConnection("Data Source=kjv.db3")
     Using da As New SQLiteDataAdapter("select * from main ORDER BY CAST(Book As Integer), CAST(Chapter AS INTEGER), CAST(Verse AS INTEGER)", connection)
       'Do the rest of your stuff here, as you already have it.
     End Using
    End Using
    The Using construct will clean up the object created when it reaches the End Using. In other words, the dataadapter and connection will both be properly cleaned up. This means creating a new connection, but thanks to connection pooling, that's not an issue, so create the connection, use it, destroy it. All clean and tidy. Whether you add a line to open the connection in the middle of that, or just let the dataadapter manage that, is up to you.

    One other point, that is even less useful is: You don't need a dataset. A dataset is just a collection of datatables. If you only have one datatable, as you have shown, then just use the datatable without a dataset. It all works about the same. On the other hand, there is no cost to the way you are doing it. One extra object....that's nothing.
    My usual boring signature: Nothing

  18. #18
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    110,350

    Re: Weird Screen Redraw Issue

    You can do it even easier than that. For one thing, a single Using statement can create multiple objects, so there's no need to nest them unless you need code between them:
    vb.net Code:
    1. Using connection As New SQLiteConnection("Data Source=kjv.db3"),
    2.       da As New SQLiteDataAdapter("select * from main ORDER BY CAST(Book As Integer), CAST(Chapter AS INTEGER), CAST(Verse AS INTEGER)", connection)
    3.     'Do the rest of your stuff here, as you already have it.
    4. End Using
    It depends on your ADO.NET provider but you can probably simplify that even further by not creating a connection yourself and letting the data adapter do it for you:
    vb.net Code:
    1. Using da As New SQLiteDataAdapter("select * from main ORDER BY CAST(Book As Integer), CAST(Chapter AS INTEGER), CAST(Verse AS INTEGER)", "Data Source=kjv.db3")
    2.     'Do the rest of your stuff here, as you already have it.
    3. End Using
    There's only reason to create the connection explicitly if you want to use it for multiple data adapters.

  19. #19

    Thread Starter
    Addicted Member
    Join Date
    Apr 2019
    Location
    Sabattus
    Posts
    234

    Re: Weird Screen Redraw Issue

    Quote Originally Posted by Shaggy Hiker View Post
    There is nothing in that code that seems too out of order. It can be improved in a few small ways, but it shouldn't be causing the problem.

    The only real issue is around the connection. At the end of the getBible method, you call connection.Clone(). Is that a typo? I would expect connection.Close, not Clone. I'm also not sure how SqlLite connections work. You never get rid of the connection, which must be a form level variable. I wouldn't expect that to cause a problem, but only because I'm making a few assumptions that might be unwarranted. Therefore, you might improve on the connection part. After all, you create the connection, then immediately check whether it is closed. It's brand new. It will be in one state or another every time, so why check? You also don't need to open it, because the datatadapter will do that. I don't have an issue with you opening it, though, because I screw that one up routinely. Dataadapters will open closed connections, but creating a datareader won't, so sometimes you do have to open it, while other times you don't, and it's an easy mistake to make. For that reason, I have no issue with always opening it yourself. Still, rather than that method, how about this:
    Code:
    Using connection As New SQLiteConnection("Data Source=kjv.db3")
     Using da As New SQLiteDataAdapter("select * from main ORDER BY CAST(Book As Integer), CAST(Chapter AS INTEGER), CAST(Verse AS INTEGER)", connection)
       'Do the rest of your stuff here, as you already have it.
     End Using
    End Using
    The Using construct will clean up the object created when it reaches the End Using. In other words, the dataadapter and connection will both be properly cleaned up. This means creating a new connection, but thanks to connection pooling, that's not an issue, so create the connection, use it, destroy it. All clean and tidy. Whether you add a line to open the connection in the middle of that, or just let the dataadapter manage that, is up to you.

    One other point, that is even less useful is: You don't need a dataset. A dataset is just a collection of datatables. If you only have one datatable, as you have shown, then just use the datatable without a dataset. It all works about the same. On the other hand, there is no cost to the way you are doing it. One extra object....that's nothing.
    Yes, clone was a typo.
    Fixed it.

    And I did adapt the "Using" as per JMC

    Thanks for the tip.
    Can't Type - Forgetful - Had Stroke = Forgive this old man!
    Website: https://pixelinkmedia.wixsite.com/frankhilton
    VSCOMM 2022 • LAZARUS 2.2.0 • Win10 • 16G RAM • Nvida GForce RTX 2060

  20. #20

    Thread Starter
    Addicted Member
    Join Date
    Apr 2019
    Location
    Sabattus
    Posts
    234

    Re: Weird Screen Redraw Issue

    Quote Originally Posted by jmcilhinney View Post
    You can do it even easier than that. For one thing, a single Using statement can create multiple objects, so there's no need to nest them unless you need code between them:
    vb.net Code:
    1. Using connection As New SQLiteConnection("Data Source=kjv.db3"),
    2.       da As New SQLiteDataAdapter("select * from main ORDER BY CAST(Book As Integer), CAST(Chapter AS INTEGER), CAST(Verse AS INTEGER)", connection)
    3.     'Do the rest of your stuff here, as you already have it.
    4. End Using
    It depends on your ADO.NET provider but you can probably simplify that even further by not creating a connection yourself and letting the data adapter do it for you:
    vb.net Code:
    1. Using da As New SQLiteDataAdapter("select * from main ORDER BY CAST(Book As Integer), CAST(Chapter AS INTEGER), CAST(Verse AS INTEGER)", "Data Source=kjv.db3")
    2.     'Do the rest of your stuff here, as you already have it.
    3. End Using
    There's only reason to create the connection explicitly if you want to use it for multiple data adapters.
    Good tip... I did adapt it and it works fine.

    Thanks JMC
    Can't Type - Forgetful - Had Stroke = Forgive this old man!
    Website: https://pixelinkmedia.wixsite.com/frankhilton
    VSCOMM 2022 • LAZARUS 2.2.0 • Win10 • 16G RAM • Nvida GForce RTX 2060

  21. #21

    Thread Starter
    Addicted Member
    Join Date
    Apr 2019
    Location
    Sabattus
    Posts
    234

    Re: Weird Screen Redraw Issue

    Okay... so it seems that I can close this thread for now.

    I have to run my app for a week or so and see if this issue pops up again.

    Thanks for everyone for your input.
    I greatly appreciate it.
    Can't Type - Forgetful - Had Stroke = Forgive this old man!
    Website: https://pixelinkmedia.wixsite.com/frankhilton
    VSCOMM 2022 • LAZARUS 2.2.0 • Win10 • 16G RAM • Nvida GForce RTX 2060

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width