Results 1 to 6 of 6

Thread: [RESOLVED] Listview adds item slow (mapped drive)

  1. #1

    Thread Starter
    Fanatic Member
    Join Date
    Nov 2016
    Location
    Slovenia
    Posts
    575

    Resolved [RESOLVED] Listview adds item slow (mapped drive)

    Hi,

    I have this code for adding items in my File Manager Listview (with adding icons & extended file properties):

    Code:
    Public shell As New Shell
    Public FolderProperty As Folder
    Public ItemProperty As FolderItem
    
    Public Sub Load_Directory(ByVal Lview As ListView, ByVal Path As String)
        
            Lview.Items.Clear()
    
            Dim items As New List(Of ListViewItem)
            Dim Directory_Item = New IO.DirectoryInfo(Path)
    
            'Extended file properties
            FolderProperty = shell.[NameSpace](Path)
      
            'Loop for files in a directory
            For Each file As IO.FileInfo In Directory_Item.EnumerateFiles()
    
                'Skip .db files
                If {".db"}.Contains(file.Extension) Then Continue For
    
                'file properties
                ItemProperty = FolderProperty.ParseName(Path.GetFileName(file.FullName))
               
                Dim LVI_File As New ListViewItem
              
                LVI_File.Tag = file.FullName
                LVI_File.ImageKey = CacheShellIcon(MyFiles.FullName)
                LVI_File.Text = file.Name
    
                LVI_File.SubItems.Add(file.LastWriteTime.ToShortDateString & " " & file.LastWriteTime.ToShortTimeString)
                'LVI_File.SubItems.Add(FolderProperty.GetDetailsOf(ItemProperty, 2).Trim())
                'LVI_File.SubItems.Add(FolderProperty.GetDetailsOf(ItemProperty, 1).Trim())
    
                items.Add(LVI_File)
    
            Next
    
            Lview.SuspendLayout()
            Lview.BeginUpdate()
    
            Lview.Items.AddRange(items.ToArray())
    
            Lview.EndUpdate()
            Lview.ResumeLayout()
    
        End Sub
    Code works fine and fast (same as Windows Explorer) when I read from local drive, but in a company we use mapped (network) drives and Listview adds items very slow. Code is a snapshot for adding files only, and It takes me about 1.6 seconds to add only 60 items in a directory. Is there any way to fasten up Listview or something else that needs to be done when working with mapped drives ?

    P.S.: I tried with VirtualMode Listview too, but It was even slower than this and icons were not added. I can post that code too, If someone thinks I should rather try that. Thanks for help in advance !!
    Last edited by LuckyLuke82; Apr 5th, 2017 at 04:00 AM.

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

    Re: Listview adds item slow (mapped drive)

    Have you actually confirmed that the issue has anything to do with the ListView? Have you timed the looped and timed the AddRange call? It's only if the AddRange call takes longer, which I doubt is the case, that this actually has anything to do with the ListView at all. It's presumably the enumeration of the remote files that is the slow part. Have you tried calling GetFiles instead? It may be that a single call is actually faster in that particular case.

    By the way, why use plurals for 'Directory_Items' and 'MyFiles' when they represent a single folder and a single file? Also, why use underscores in some places and not others and start some variable names with upper case and some with lower case? The more inconsistent you are, the more confusing your code will be to others and also to yourself when you come back to it later.

  3. #3

    Thread Starter
    Fanatic Member
    Join Date
    Nov 2016
    Location
    Slovenia
    Posts
    575

    Re: Listview adds item slow (mapped drive)

    Have you timed the looped and timed the AddRange call? It's only if the AddRange call takes longer, which I doubt is the case, that this actually has anything to do with the ListView at all.
    Yes I timed normal .Add method and this .AddRange method. AddRange method is faster.

    It's presumably the enumeration of the remote files that is the slow part. Have you tried calling GetFiles instead? It may be that a single call is actually faster in that particular case.
    YES, you're right about that. So what to do with It - how to fasten up enumeration ?


    Have you tried calling GetFiles instead?
    Another yes. Same effect.

    By the way, why use plurals for 'Directory_Items' and 'MyFiles' when they represent a single folder and a single file?
    I never post a code with my original variable names, because they are written in my language. It would only be confusing to you all.

    Also, why use underscores in some places and not others and start some variable names with upper case and some with lower case? The more inconsistent you are, the more confusing your code will be to others and also to yourself when you come back to it later.
    Ok, I'll edit this, my bad. I'm just trying to type something in a way that is obvious for anyone.
    Last edited by LuckyLuke82; Apr 5th, 2017 at 04:07 AM.

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

    Re: Listview adds item slow (mapped drive)

    Quote Originally Posted by LuckyLuke82 View Post
    Yes I timed normal .Add method and this .AddRange method. AddRange method is faster.
    That wasn't what I was asking. I meant had to timed the AddRange call for local and remote folders because I suspect that it will be the same and thus the issue is nothing to do with the ListView.
    Quote Originally Posted by LuckyLuke82 View Post
    YES, you're right about that. So what to do with It - how to fasten up enumeration ?
    That seems to suggest that my suspicions were correct. There may not be anything you can do about it. If that's how long it takes your machine to get folder contents from a remote machine over the network then your app can't do anything about it. What do you see if you try to view that folder in File Explorer?
    Quote Originally Posted by LuckyLuke82 View Post
    I never post a code with my original variable names, because they are written in my language. It would only be confusing to you all.
    Good plan, for everyone's sake.
    Quote Originally Posted by LuckyLuke82 View Post
    Ok, I'll edit this, my bad. I'm just trying to type something in a way that is obvious for anyone.
    If you don't already, you should settle on a naming convention for your own language and just use the same for modified code to post here. Microsoft recommend no underscores and lower-case for the first letter of a variable. Unless you have a good reason to do otherwise, you should follow that convention.

  5. #5

    Thread Starter
    Fanatic Member
    Join Date
    Nov 2016
    Location
    Slovenia
    Posts
    575

    Re: Listview adds item slow (mapped drive)

    If that's how long it takes your machine to get folder contents from a remote machine over the network then your app can't do anything about it. What do you see if you try to view that folder in File Explorer?
    No, PC opens those directories just fine, Explorer works as normal, we just have shared network drives. I'm trying to open same path as UNC path, currently how I enumerate directories is with a local path, like "C:\My documents". But nothing I try seems to work, I allways get "path is not supported format" error. A path in my File manager actually looks like "Lucky(\\servername\usersgroup1$)(D: )My documents". Do you know what should I look for to try enumerating mapped drives, how to correctly insert path string ?

  6. #6

    Thread Starter
    Fanatic Member
    Join Date
    Nov 2016
    Location
    Slovenia
    Posts
    575

    Re: Listview adds item slow (mapped drive)

    I tried using UNC path, but still same result. Doing more testing I noticed that enumeration for files and folders is mostly slow because of extracting icons from shell32.dll. Without that now my folder with 60 items opens in 0.5 sec, which is about 1 second faster. Still not fast, but much faster. Since this is not a problem that Listview causes I'm closing this thread and will open a new one instead.

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