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. The Lounge
  3. That's Cool

That's Cool

Scheduled Pinned Locked Moved The Lounge
mobiledesignsysadminannouncement
21 Posts 8 Posters 6 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 Lost User

    You have 256 tasks, which at least originally took several seconds, but reliably end, no matter if successful or not. They can be carried out independently without any data synchronization, you just have to go through the results afterwards. That screams for parallel processing. The conditions could not be better. I can't believe that this is a real surprise to an old trapper like you. Just out of curiosity: Did you really use 256 instances of a custom thread class or simply use the Parallel class, something like a Parallel.For() loop?

    realJSOPR Offline
    realJSOPR Offline
    realJSOP
    wrote on last edited by
    #21

    I did it this way:

    //--------------------------------------------------------------------------------
    public static void GetLanMachinesThreaded(System.Windows.Threading.Dispatcher dispatcher,
    List<HostAddress> subnet,
    Control control,
    bool setItemsSource=false)
    {
    List<Task> tasks = new List<Task>();
    foreach(HostAddress item in subnet)
    {
    var t = Task.Factory.StartNew(() => { item.FindHost(); });
    tasks.Add(t);
    }
    Task.Factory.ContinueWhenAll(tasks.ToArray(), result =>
    {
    subnet.RemoveAll(item => item.Host == null || item.Shares.Count == 0);
    if (control != null)
    {
    if (control is ItemsControl && setItemsSource)
    {
    dispatcher.BeginInvoke(new Action(() => ((ItemsControl)control).ItemsSource = subnet));
    }
    dispatcher.BeginInvoke(new Action(() => control.Focus()));
    }
    });
    }

    The item.FindHost method searches for the IP's specified in the subnet parameter, and then looks for disk shares on hosts that were found. once that's completed, it removes shares that are specified in a filter list (default shares, and anything that isn't a disk share), and then removes any hosts that end up with no shares found. If the disks are spun up from recent access, it now takes about 25 seconds (because of the disk share enumeration). If the disks aren't spun up, it takes almost twice as long. Since this only happens when the user specifically wants to add a new shared media source, I think the performance is acceptable, and I'm not sure it could be made much (if any) faster.

    ".45 ACP - because shooting twice is just silly" - JSOP, 2010
    -----
    You can never have too much ammo - unless you're swimming, or on fire. - JSOP, 2010
    -----
    "Why don't you tie a kerosene-soaked rag around your ankles so the ants won't climb up and eat your candy ass." - Dale Earnhardt, 1997

    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