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. C#
  4. Custom DataGridColumnStyle with images eats up system resources / cpu

Custom DataGridColumnStyle with images eats up system resources / cpu

Scheduled Pinned Locked Moved C#
helpcsswindows-admintutorialquestion
4 Posts 2 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.
  • L Offline
    L Offline
    Larantz
    wrote on last edited by
    #1

    Hi everyone. I'm working on an application that displays files with name and path ++ in a DataGrid. One day I came over a ListView project on the inet that could show images / icons + text in one column, so I started working on my own DataGridColumnStyle to try and achieve the same result. Only problem is that its really cpu-consuming when it retrieves the images and displays them. In my custom columnstyle paint method I retrieve the filname, then I extract the extension from the filename, look up extension in Registry to find default application, and at last I get the path to the default Icon file. Finally, I can extract the icon using

    hImgSmall = Win32.SHGetFileInfo(filePath, 0, ref shinfo,
    (uint)Marshal.SizeOf(shinfo),
    Win32.SHGFI_ICON |
    Win32.SHGFI_SMALLICON);

    I was wondering if anyone has been working with anything similiar and that might have some hints/tips as how to make this less cpu consuming. Maybe a more efficient way of locating the icons. I recon all the "lookups" in registry is what makes this so slow. Might help with double-buffering too? The images and text are drawn to the screen. :S -Larantz-

    W 1 Reply Last reply
    0
    • L Larantz

      Hi everyone. I'm working on an application that displays files with name and path ++ in a DataGrid. One day I came over a ListView project on the inet that could show images / icons + text in one column, so I started working on my own DataGridColumnStyle to try and achieve the same result. Only problem is that its really cpu-consuming when it retrieves the images and displays them. In my custom columnstyle paint method I retrieve the filname, then I extract the extension from the filename, look up extension in Registry to find default application, and at last I get the path to the default Icon file. Finally, I can extract the icon using

      hImgSmall = Win32.SHGetFileInfo(filePath, 0, ref shinfo,
      (uint)Marshal.SizeOf(shinfo),
      Win32.SHGFI_ICON |
      Win32.SHGFI_SMALLICON);

      I was wondering if anyone has been working with anything similiar and that might have some hints/tips as how to make this less cpu consuming. Maybe a more efficient way of locating the icons. I recon all the "lookups" in registry is what makes this so slow. Might help with double-buffering too? The images and text are drawn to the screen. :S -Larantz-

      W Offline
      W Offline
      Wjousts
      wrote on last edited by
      #2

      I haven't tried anything like what you are doing, but one thought struck me. Are you looking up a lot of files with the same extension? If so could you maintain your own list of icons using the extension as a key (maybe the dictonary class would be good for this?) so that you only need to look in the registry the first time you encounter an extension? That would cut down on keep having to recreate the same icon. The procedure would be something like this: 1) Get extension from filename 2) Look in my list to see if I already have a bitmap 3) If I already have it, use it and we're done 4) If we don't have it look it up in the registry and add it to our list

      L 2 Replies Last reply
      0
      • W Wjousts

        I haven't tried anything like what you are doing, but one thought struck me. Are you looking up a lot of files with the same extension? If so could you maintain your own list of icons using the extension as a key (maybe the dictonary class would be good for this?) so that you only need to look in the registry the first time you encounter an extension? That would cut down on keep having to recreate the same icon. The procedure would be something like this: 1) Get extension from filename 2) Look in my list to see if I already have a bitmap 3) If I already have it, use it and we're done 4) If we don't have it look it up in the registry and add it to our list

        L Offline
        L Offline
        Larantz
        wrote on last edited by
        #3

        Thx for the tip. I've been thinking about something like that too. I'll try and implement it at work tomorrow. Still on the lookout for more efficient ways of retrieving icons if anyone has a tip. -Larantz-

        1 Reply Last reply
        0
        • W Wjousts

          I haven't tried anything like what you are doing, but one thought struck me. Are you looking up a lot of files with the same extension? If so could you maintain your own list of icons using the extension as a key (maybe the dictonary class would be good for this?) so that you only need to look in the registry the first time you encounter an extension? That would cut down on keep having to recreate the same icon. The procedure would be something like this: 1) Get extension from filename 2) Look in my list to see if I already have a bitmap 3) If I already have it, use it and we're done 4) If we don't have it look it up in the registry and add it to our list

          L Offline
          L Offline
          Larantz
          wrote on last edited by
          #4

          I implemented iconbuffering now but it still flicks and takes up resources. I'll try with double-buffering. That should atleast take care of the flickering. When it comes to resources, maybe I can't improve that considering the fact that it's many paint operations. -Larantz-

          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