Results 1 to 11 of 11

Thread: [RESOLVED] Listview slowness

  1. #1

    Thread Starter
    Frenzied Member
    Join Date
    Nov 1999
    Posts
    1,331

    Resolved [RESOLVED] Listview slowness

    So I have this app that has a treeview and listview on it. Basically a mini explorer window without any bells or whistles. All it does is shows icons that are shortcuts loaded from the local C drive. Been working for years just fine. I have noticed that recently the listview part is slow on folders that have a lot of icons to show. I say a lot of icons but at most it could be 170. Not a lot. If I click on a folder that has very few icons, say 10, and leave it there for a few hours, then click on the folder that has 150 icons, it almost acts like the app is crashing. It states Not Responding and then a few seconds later, more like 10secs, it finally comes up and looks fine. Curious if a .NET update has changed something? Only acts slow when you don't use it for a few hours. Once you do use it and go back and forth, it's pretty fast. Thoughts??? Anybody else experience something like this?

    Here is the sub that loads the icons in the listview

    Code:
    Public Sub ListFoldersFiles(ByVal apath As String, ByVal lvTemp As ListView, ByVal imgLtemp As ImageList)
            ' Create a reference to the current directory.
            Dim di As New DirectoryInfo(apath)
    
            ' MsgBox(di.ToString)
            If Directory.Exists(di.ToString) Then
    
                ' Create an array representing the files in the current directory.
                Dim fi As FileInfo() = di.GetFiles()
                Dim fiTemp As FileInfo
                'Dim i As Short
                Array.Sort(fi, New compclass(SortOrder.Ascending))
    
                lvTemp.Items.Clear()
                'lvTemp.Sorting = SortOrder.Ascending
                'i = 0
                'MsgBox(fi.Length)
                ' Loop through each file in the directory
                lvTemp.BeginUpdate()
    
                For Each fiTemp In fi
    
                    Dim strImageKey As String = String.Empty
                    Try
                        ' gets the icon from file
                        Dim ico As Icon = Icon.ExtractAssociatedIcon(apath & fiTemp.Name)
                        If ico IsNot Nothing Then
                            Dim bmp As Bitmap = ico.ToBitmap()
                            strImageKey = bmp.GetHashCode.ToString
                            imgLtemp.Images.Add(strImageKey, bmp)
                            Form1.ImageList3.Images.Add(strImageKey, bmp)
    
                        End If
                    Catch ex As Exception
    
                    End Try
    
                    ' split the extension off so we can use just the text.
    
                    Dim rFileName As Array = Split(fiTemp.Name, ".")
                    'MsgBox(rFileName(0))
                    Dim fname As String = rFileName(0)
                    ' lvTemp.Items.Add(fiTemp.Name, rFileName(0), strImageKey)
                    ' add full name to tag so we can call it later seeing how we 
                    ' don't use the extension for the text.
                    m_Shortcut = New ShellShortcut(apath & fiTemp.Name)
                    Dim item As New ListViewItem(fname, imgLtemp.Images.Count - 1) With {.Tag = apath & fiTemp.Name, .ToolTipText = m_Shortcut.Description}
                    lvTemp.Items.Add(item)
                    ' used in details view
                    If Form1.tvFolders.SelectedNode.Name <> "Home" Then
                        item.SubItems.Add(Form1.tvFolders.SelectedNode.Parent.Name)
                        item.SubItems.Add(m_Shortcut.Description) ' adds the tooltip text to the description column
                    Else
                        item.SubItems.Add("Home")
                        item.SubItems.Add(m_Shortcut.Description) ' adds the tooltip text to the description column
                    End If
                    item.SubItems.Add(fname.ToString)
    
                Next fiTemp
                lvTemp.EndUpdate()
            End If
        End Sub

  2. #2
    eXtreme Programmer .paul.'s Avatar
    Join Date
    May 2007
    Location
    Chelmsford UK
    Posts
    25,464

    Re: Listview slowness

    Why leave it open for a couple of hours? You could use a timer and the idle time to shut it down

  3. #3
    eXtreme Programmer .paul.'s Avatar
    Join Date
    May 2007
    Location
    Chelmsford UK
    Posts
    25,464

    Re: Listview slowness

    If that’s not useful, you haven’t posted your relevant code. There may be some way to refresh after a set time…

  4. #4
    King of sapila
    Join Date
    Oct 2006
    Location
    Greece
    Posts
    6,597

    Re: Listview slowness

    Maybe use virtualmode to cache your items?
    https://learn.microsoft.com/en-us/do...owsdesktop-6.0
    ἄνδρα μοι ἔννεπε, μοῦσα, πολύτροπον, ὃς μάλα πολλὰ
    πλάγχθη, ἐπεὶ Τροίης ἱερὸν πτολίεθρον ἔπερσεν·

  5. #5
    PowerPoster jdc2000's Avatar
    Join Date
    Oct 2001
    Location
    Idaho Falls, Idaho USA
    Posts
    2,393

    Re: Listview slowness

    That sounds like a typical icon cache issue from Windows. The same thing happens in Windows Explorer for folders with thumbnail views.

  6. #6

    Thread Starter
    Frenzied Member
    Join Date
    Nov 1999
    Posts
    1,331

    Re: Listview slowness

    Quote Originally Posted by .paul. View Post
    If that’s not useful, you haven’t posted your relevant code. There may be some way to refresh after a set time…
    We can't close it, it runs all day with no way to kill it except task manager. But yes, I do have it refreshing every hour and still see the slowness

    Quote Originally Posted by sapator View Post
    Maybe use virtualmode to cache your items?
    https://learn.microsoft.com/en-us/do...owsdesktop-6.0
    I did look into this, and I would have to really read up on it as it sounded a little bit difficult to impliment in my scenario

    Quote Originally Posted by jdc2000 View Post
    That sounds like a typical icon cache issue from Windows. The same thing happens in Windows Explorer for folders with thumbnail views.
    Thats interesting, I may not have paid attention to that. I show icons on all three modes, details and large/small icons. The default display is small icons. So it sounds like I'm stuck with it lol

  7. #7

    Thread Starter
    Frenzied Member
    Join Date
    Nov 1999
    Posts
    1,331

    Re: Listview slowness

    Scoring the internet, I did come across a bug in .NET5.x that is doing my exact problem. But we are on 4.8. The bug showed that 4.7.2 didn't experience the issue so I updated the code to run on 4.7.2 and it showed the same issues. So then I rewrote the code to do virtualmode for the listview and it was way worse, even running in cache mode. So I guess I will try .NET 5.x and see if it shows the same symptoms.

    [edit]
    I take that back. There isn't a .NET 5 framework lol
    [/edit]
    Last edited by phpman; Sep 26th, 2022 at 09:29 AM.

  8. #8

    Thread Starter
    Frenzied Member
    Join Date
    Nov 1999
    Posts
    1,331

    Re: Listview slowness

    So I have found that it is not the listview that is the slowness. It is reading the 170 files from the directory that takes 11sec, then load into the listview with is about 2 seconds. Any better way of getting files from a directory than what I am currently doing above? I don't think it is the ico extraction as I disabled that and it still took 10sec. Ideas?

  9. #9
    Banned
    Join Date
    Sep 2022
    Posts
    16

    Re: Listview slowness

    List Adapter:
    public class MyListAdapter extends ArrayAdapter < SettingsItem > {

    Context context;
    List < SettingsItem > items;
    public MyListAdapter(Context context, int resource, List < SettingsItem > objects) {
    super(context, resource, objects);
    this.context = context;
    items = objects;
    }

    @Override
    public View getView(int position, View itemView, ViewGroup parent) {

    ViewHolder holder;
    if (itemView == null) {
    LayoutInflater inflater = ((Activity) context).getLayoutInflater();
    itemView = inflater.inflate(R.layout.settings_items, parent, false);

    holder = new ViewHolder();
    holder.imageView = (ImageView) itemView.findViewById(R.id.item_icon);
    holder.textView = (TextView) itemView.findViewById(R.id.item_text);

    itemView.setTag(holder);
    } else {
    holder = (ViewHolder) itemView.getTag();
    }

    SettingsItem settingsItem = items.get(position);

    if (settingsItem != null) {
    holder.textView.setText(settingsItem.getName());
    new ImageDownloaderTask(holder.imageView, getContext(), settingsItem.getIcon_id()).execute();
    }
    return itemView;
    }
    static class ViewHolder {
    ImageView imageView;
    TextView textView;
    }
    }

  10. #10
    eXtreme Programmer .paul.'s Avatar
    Join Date
    May 2007
    Location
    Chelmsford UK
    Posts
    25,464

    Re: Listview slowness

    Quote Originally Posted by mmarkgilbert View Post
    List Adapter:
    public class MyListAdapter extends ArrayAdapter < SettingsItem > {

    Context context;
    List < SettingsItem > items;
    public MyListAdapter(Context context, int resource, List < SettingsItem > objects) {
    super(context, resource, objects);
    this.context = context;
    items = objects;
    }

    @Override
    public View getView(int position, View itemView, ViewGroup parent) {

    ViewHolder holder;
    if (itemView == null) {
    LayoutInflater inflater = ((Activity) context).getLayoutInflater();
    itemView = inflater.inflate(R.layout.settings_items, parent, false);

    holder = new ViewHolder();
    holder.imageView = (ImageView) itemView.findViewById(R.id.item_icon);
    holder.textView = (TextView) itemView.findViewById(R.id.item_text);

    itemView.setTag(holder);
    } else {
    holder = (ViewHolder) itemView.getTag();
    }

    SettingsItem settingsItem = items.get(position);

    if (settingsItem != null) {
    holder.textView.setText(settingsItem.getName());
    new ImageDownloaderTask(holder.imageView, getContext(), settingsItem.getIcon_id()).execute();
    }
    return itemView;
    }
    static class ViewHolder {
    ImageView imageView;
    TextView textView;
    }
    }
    This is a VB forum. That’s not helpful…

  11. #11

    Thread Starter
    Frenzied Member
    Join Date
    Nov 1999
    Posts
    1,331

    Re: Listview slowness

    Well, don't you just love chasing the rabbit down the deep dark hole just to find out that it was the antivirus software dragging you down? LOL. It was the real-time scanning that as making the function that read the files to be extremely slow. With no real time scanning enabled the process took 2sec, compared to 11sec. I will consider this thread close.

    Thanks to those that replied.

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